DineshKumar1329 commited on
Commit
f32744b
·
verified ·
1 Parent(s): b1f3701

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +11 -10
README.md CHANGED
@@ -44,28 +44,29 @@ This repository contains a ResNet-based convolutional neural network trained to
44
  import torch
45
  from torchvision import transforms
46
  from PIL import Image
 
47
 
48
- # Load the model
49
- model = torch.hub.load('DineshKumar1329/DogCat_Classifier', 'resnet_cat_dog_classifier')
50
-
51
- # Define the transformation
52
  transform = transforms.Compose([
53
  transforms.Resize((128, 128)),
54
  transforms.ToTensor(),
55
  transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
56
  ])
57
 
58
- # Load an image
 
 
 
59
  image_path = 'path/to/your/image.jpg'
60
  image = Image.open(image_path)
61
  image = transform(image)
62
  image = image.unsqueeze(0) # Add batch dimension
63
 
64
  # Make a prediction
65
- model.eval()
66
- with torch.no_grad():
67
- outputs = model(image)
68
- temp, predicted = torch.max(outputs, 1)
69
 
70
  # Output the prediction
71
- print(f'The predicted class for the image is: {"Cat" if predicted.item() == 0 else "Dog"}')
 
44
  import torch
45
  from torchvision import transforms
46
  from PIL import Image
47
+ from transformers import pipeline
48
 
49
+ # Define the image transformation
 
 
 
50
  transform = transforms.Compose([
51
  transforms.Resize((128, 128)),
52
  transforms.ToTensor(),
53
  transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
54
  ])
55
 
56
+ # Load the model from Hugging Face
57
+ pipe = pipeline("image-classification", model="DineshKumar1329/DogCat_Classifier")
58
+
59
+ # Load and preprocess an image
60
  image_path = 'path/to/your/image.jpg'
61
  image = Image.open(image_path)
62
  image = transform(image)
63
  image = image.unsqueeze(0) # Add batch dimension
64
 
65
  # Make a prediction
66
+ result = classifier(image_path)
67
+
68
+ # Extract the predicted label
69
+ predicted_label = result[0]['label']
70
 
71
  # Output the prediction
72
+ print(f'The predicted class for the image is: {predicted_label}')