Minbz commited on
Commit
f62107e
·
verified ·
1 Parent(s): 1852ded

Added resizing preprocessing to 224*224

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -5,17 +5,19 @@ PATH = "./4-15_ViT-B16_Lung3_v1"
5
  model = TFAutoModel.from_pretrained(PATH)
6
  tokenizer = AutoTokenizer.from_pretrained(PATH)
7
 
8
-
9
  # Define preprocessing function
10
- # def preprocess_image(image):
11
- # # Add preprocessing steps here (e.g., resizing, normalization)
12
- # # Return preprocessed image
13
- # return image
 
 
 
14
 
15
  # Define inference function
16
- def predict(preprocessed_image):
17
  # Preprocess the image
18
- # preprocessed_image = preprocess_image(image)
19
 
20
  # Convert preprocessed image to input format expected by the model
21
  inputs = tokenizer(preprocessed_image, return_tensors="tf")
@@ -33,7 +35,7 @@ def predict(preprocessed_image):
33
  image_component = gr.Image(type="numpy", label="Chest X-ray Image")
34
  label_component = gr.Label(label="Classification result", num_top_classes=1)
35
  description = ""
36
- title = "Pneumonia Classifier 🐣"
37
 
38
  demo = gr.Interface(fn=predict, inputs=image_component, outputs=label_component, description=description, title=title)
39
 
 
5
  model = TFAutoModel.from_pretrained(PATH)
6
  tokenizer = AutoTokenizer.from_pretrained(PATH)
7
 
 
8
  # Define preprocessing function
9
+ def preprocess_image(image):
10
+ transform_test = transforms.Compose([
11
+ transforms.Resize((224, 224)),
12
+ ])
13
+
14
+ scaled_img = transform_test(image)
15
+ return scaled_img
16
 
17
  # Define inference function
18
+ def predict(image):
19
  # Preprocess the image
20
+ preprocessed_image = preprocess_image(image)
21
 
22
  # Convert preprocessed image to input format expected by the model
23
  inputs = tokenizer(preprocessed_image, return_tensors="tf")
 
35
  image_component = gr.Image(type="numpy", label="Chest X-ray Image")
36
  label_component = gr.Label(label="Classification result", num_top_classes=1)
37
  description = ""
38
+ title = "Pneumonia Classifier"
39
 
40
  demo = gr.Interface(fn=predict, inputs=image_component, outputs=label_component, description=description, title=title)
41