Added dependencies in requirements.txt file.
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
# Import libraries
|
||||||
|
from PIL import Image, UnidentifiedImageError
|
||||||
|
from transformers import ViTImageProcessor, ViTForImageClassification
|
||||||
|
|
||||||
|
# Specify the local directory where the model files are stored
|
||||||
|
local_model_path = '/home/overnion/Status200/models/pretrained'
|
||||||
|
|
||||||
|
# Load the image processor and model from the local directory
|
||||||
|
image_processor = ViTImageProcessor.from_pretrained(local_model_path)
|
||||||
|
model = ViTForImageClassification.from_pretrained(
|
||||||
|
local_model_path,
|
||||||
|
ignore_mismatched_sizes=True
|
||||||
|
)
|
||||||
|
|
||||||
|
# Load image
|
||||||
|
try:
|
||||||
|
image = Image.open('/home/overnion/Status200/models/samples/apple.png')
|
||||||
|
# Convert the image to RGB if it's not already
|
||||||
|
if (image.mode != 'RGB'):
|
||||||
|
image = image.convert('RGB')
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("Error: Image file not found.")
|
||||||
|
exit()
|
||||||
|
except UnidentifiedImageError:
|
||||||
|
print("Error: Unable to open image. Check the file type.")
|
||||||
|
exit()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"An error occurred: {e}")
|
||||||
|
exit()
|
||||||
|
|
||||||
|
# Preparing the image for the model
|
||||||
|
inputs = image_processor(images=image, return_tensors="pt")
|
||||||
|
|
||||||
|
# Make the prediction
|
||||||
|
outputs = model(**inputs)
|
||||||
|
logits = outputs.logits
|
||||||
|
predicted_class_idx = logits.argmax(-1).item()
|
||||||
|
|
||||||
|
# Print the predicted class
|
||||||
|
print("Predicted class:", model.config.id2label[predicted_class_idx])
|
||||||
|
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
certifi==2025.1.31
|
||||||
|
charset-normalizer==3.4.1
|
||||||
|
filelock==3.17.0
|
||||||
|
fsspec==2025.2.0
|
||||||
|
huggingface-hub==0.29.1
|
||||||
|
idna==3.10
|
||||||
|
Jinja2==3.1.5
|
||||||
|
MarkupSafe==3.0.2
|
||||||
|
mpmath==1.3.0
|
||||||
|
networkx==3.4.2
|
||||||
|
numpy==2.2.3
|
||||||
|
nvidia-cublas-cu12==12.4.5.8
|
||||||
|
nvidia-cuda-cupti-cu12==12.4.127
|
||||||
|
nvidia-cuda-nvrtc-cu12==12.4.127
|
||||||
|
nvidia-cuda-runtime-cu12==12.4.127
|
||||||
|
nvidia-cudnn-cu12==9.1.0.70
|
||||||
|
nvidia-cufft-cu12==11.2.1.3
|
||||||
|
nvidia-curand-cu12==10.3.5.147
|
||||||
|
nvidia-cusolver-cu12==11.6.1.9
|
||||||
|
nvidia-cusparse-cu12==12.3.1.170
|
||||||
|
nvidia-cusparselt-cu12==0.6.2
|
||||||
|
nvidia-nccl-cu12==2.21.5
|
||||||
|
nvidia-nvjitlink-cu12==12.4.127
|
||||||
|
nvidia-nvtx-cu12==12.4.127
|
||||||
|
packaging==24.2
|
||||||
|
pillow==11.1.0
|
||||||
|
PyYAML==6.0.2
|
||||||
|
regex==2024.11.6
|
||||||
|
requests==2.32.3
|
||||||
|
safetensors==0.5.2
|
||||||
|
setuptools==75.8.0
|
||||||
|
sympy==1.13.1
|
||||||
|
tokenizers==0.21.0
|
||||||
|
torch==2.6.0
|
||||||
|
torchvision==0.21.0
|
||||||
|
tqdm==4.67.1
|
||||||
|
transformers==4.49.0
|
||||||
|
triton==3.2.0
|
||||||
|
typing_extensions==4.12.2
|
||||||
|
urllib3==2.3.0
|
||||||
Reference in New Issue
Block a user