Medvira commited on
Commit
0fc8295
·
verified ·
1 Parent(s): d5bf70e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -6,6 +6,9 @@ import gdown
6
  from PIL import Image
7
  import numpy as np
8
 
 
 
 
9
  # Define the model URL and output path
10
  model_url = "https://drive.google.com/file/d/18HYScsRJuRmfzL0E0BW35uaA542Vd5M5/view?usp=sharing"
11
  model_path = os.path.join(os.getcwd(),"bone_age_model.onnx")
@@ -26,10 +29,15 @@ def inference(sample_name):
26
  predicted_age = (outputs[0]*41.172)+127.329
27
  # Get the image data from the MetaTensor and convert it to a format PIL can handle
28
  image_data = sample['path'].numpy()
29
- image_data = (image_data * 255).astype(np.uint8) # Assuming the image data is normalized
30
- image_data = np.squeeze(image_data) # Remove any singleton dimensions if necessary
31
- image = Image.fromarray(image_data.transpose(1, 2, 0)) # Convert to HWC format
32
-
 
 
 
 
 
33
  return age, predicted_age[0][0], image
34
 
35
  # List of sample file names
 
6
  from PIL import Image
7
  import numpy as np
8
 
9
+ means = np.array([0.485, 0.456, 0.406])
10
+ stds = np.array([0.229, 0.224, 0.225])
11
+
12
  # Define the model URL and output path
13
  model_url = "https://drive.google.com/file/d/18HYScsRJuRmfzL0E0BW35uaA542Vd5M5/view?usp=sharing"
14
  model_path = os.path.join(os.getcwd(),"bone_age_model.onnx")
 
29
  predicted_age = (outputs[0]*41.172)+127.329
30
  # Get the image data from the MetaTensor and convert it to a format PIL can handle
31
  image_data = sample['path'].numpy()
32
+ # Denormalize the image data
33
+ for i in range(3): # Assuming the image has 3 channels
34
+ image_data[i,:,:] = image_data[i,:,:] * stds[i] + means[i]
35
+ # Rescale to [0, 1]
36
+ # Convert to [0, 255] and to uint8
37
+ image_data = (image_data * 255).astype(np.uint8)
38
+ # Remove any singleton dimensions if necessary
39
+ image_data = np.moveaxis(image_data,0,-1)
40
+ image = Image.fromarray(image_data)
41
  return age, predicted_age[0][0], image
42
 
43
  # List of sample file names