Spaces:
Sleeping
Sleeping
First commit of app.py
Browse filesThis is the hosted inference engine for the fine-tuned ViT model on approximately 35k images of Mammograms from the Mammogram V1 dataset.
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForImageClassification, Trainer, ViTImageProcessor, ViTForImageClassification, pipeline, AutoImageProcessor
|
3 |
+
from torchvision import transforms
|
4 |
+
|
5 |
+
model = AutoModelForImageClassification.from_pretrained("Nicole-M/Dataset1-ViT")
|
6 |
+
image_processor = AutoImageProcessor.from_pretrained("Nicole-M/Dataset1-ViT")
|
7 |
+
clf = pipeline(model=model, task="image-classification", image_processor=image_processor)
|
8 |
+
|
9 |
+
class_names = ['Benign', 'Malignant']
|
10 |
+
|
11 |
+
def predict_image(img):
|
12 |
+
img=img.reshape(224,224,3)
|
13 |
+
img = transforms.ToPILImage()(img)
|
14 |
+
prediction=clf.predict(img)
|
15 |
+
return {class_names[i]: float(prediction[i]["score"]) for i in range(2)}
|
16 |
+
|
17 |
+
image = gr.inputs.Image(shape=(224,224))
|
18 |
+
label = gr.outputs.Label(num_top_classes=2)
|
19 |
+
|
20 |
+
gr.Interface(fn=predict_image, inputs=image, outputs=label,interpretation='default').launch()
|