Muhammad Firdho commited on
Commit
53aa608
1 Parent(s): b527bc5

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +70 -0
README.md ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🎯 # Image Classification Model for Medical Waste Classification
2
+
3
+ This is an image classification model trained to classify medical waste into 4 categories, namely cytotoxic, infectious, pathological, and pharmaceutical. The model is based on the Inception v3 architecture and has been adapted to a specific dataset for the task of medical waste classification.
4
+
5
+ # 🎯 Model Description
6
+
7
+ The model is based on the Inception v3 architecture with modifications to the fully connected layers for adapting it to the specific image classification task. The architecture consists of a feature extractor followed by a global average pooling layer and fully connected layers with ReLU activation and dropout.
8
+
9
+ # 🎯 Usage
10
+
11
+ You can use the model that I have saved in pt format as follows:
12
+
13
+ ```python
14
+
15
+ import torch
16
+ from torchvision import transforms
17
+ from PIL import Image
18
+ import matplotlib.pyplot as plt
19
+ import numpy as np
20
+
21
+ def predict_image(image_path, model, transform, class_names):
22
+ # Load the image
23
+ image = Image.open(image_path)
24
+ # Apply transformations
25
+ image = transform(image).unsqueeze(0) # Add batch dimension
26
+
27
+ # Set the model to evaluation mode
28
+ model.eval()
29
+
30
+ # Make predictions
31
+ with torch.no_grad():
32
+ outputs = model(image.to(device))
33
+ _, predicted = torch.max(outputs, 1)
34
+ predicted_class = predicted.item()
35
+ predicted_label = class_names[predicted_class]
36
+ probabilities = torch.softmax(outputs, dim=1)[0]
37
+ confidence = probabilities[predicted_class].item()
38
+ return predicted_class, predicted_label, confidence
39
+
40
+ # Define transformation to be applied to the input image
41
+ image_transform = transforms.Compose([
42
+ transforms.Resize((299, 299)), # Resize to match InceptionV3 input size
43
+ transforms.ToTensor(),
44
+ # You can add more transformations such as normalization if needed
45
+ ])
46
+
47
+ # Load the trained model
48
+ model = torch.load('__directory where you save the model__')
49
+ model.to(device)
50
+
51
+ # Load class names (assuming you have a list of class names)
52
+ class_names = ['cytotoxic', 'infectious', 'pathological', 'pharmaceutical']
53
+
54
+ # Provide the path to the image you want to predict
55
+ image_path = '__the directory where you store the images you want to classify__'
56
+
57
+ # Load the true label (assuming you have it)
58
+ true_label = 'pathological'
59
+
60
+ # Predict the class label
61
+ predicted_class, predicted_label, confidence = predict_image(image_path, model, image_transform, class_names)
62
+
63
+ # Display the image
64
+ image = Image.open(image_path)
65
+ plt.imshow(np.array(image))
66
+ plt.axis('off')
67
+ plt.title(f'True Class: {true_label} \n Predicted Class: {predicted_label} (Confidence: {confidence*100:.2f}%)')
68
+ plt.show()
69
+
70
+ ```