yuragoithf commited on
Commit
d22dc1f
·
1 Parent(s): 363ec41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -48,15 +48,15 @@ def dice_coef(y_true, y_pred, smooth=1):
48
  # Load the model
49
  seg_model = keras.models.load_model('seg_unet_model.h5', custom_objects={'Combo_loss': Combo_loss, 'dice_coef': dice_coef})
50
 
51
- inputs = gr.inputs.Image(type="pil", label="Upload an image")
52
  image_output = gr.outputs.Image(type="pil", label="Output Image")
53
  # outputs = gr.outputs.HTML() #uncomment for single class output
54
 
55
 
56
  def gen_pred(img, model=seg_model):
57
- pil_image = img.convert('RGB')
58
- open_cv_image = np.array(pil_image)
59
- img = open_cv_image[:, :, ::-1].copy()
60
  # # img = cv2.imread("./003e2c95d.jpg")
61
  img = img[::IMG_SCALING[0], ::IMG_SCALING[1]]
62
  img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
@@ -64,7 +64,8 @@ def gen_pred(img, model=seg_model):
64
  img = tf.expand_dims(img, axis=0)
65
  pred = model.predict(img)
66
  pred = np.squeeze(pred, axis=0)
67
- pil_img = Image.fromarray(pred, 'RGB')
 
68
  # im = Image.fromarray((pred * 255).astype(np.uint8))
69
  # img_bytes = pred.tobytes()
70
  # nparr = np.frombuffer(img_bytes, np.byte)
@@ -77,7 +78,7 @@ description = "Upload an image and get prediction mask"
77
  # css_code='body{background-image:url("file=wave.mp4");}'
78
 
79
  gr.Interface(fn=gen_pred,
80
- inputs=[gr.Image(type='pil')],
81
  outputs=gr.Image(type='numpy'),
82
  title=title,
83
  examples=[["003e2c95d.jpg"], ["003b50a15.jpg"], ["003b48a9e.jpg"], ["0038cbe45.jpg"], ["00371aa92.jpg"]],
 
48
  # Load the model
49
  seg_model = keras.models.load_model('seg_unet_model.h5', custom_objects={'Combo_loss': Combo_loss, 'dice_coef': dice_coef})
50
 
51
+ # inputs = gr.inputs.Image(type="pil", label="Upload an image")
52
  image_output = gr.outputs.Image(type="pil", label="Output Image")
53
  # outputs = gr.outputs.HTML() #uncomment for single class output
54
 
55
 
56
  def gen_pred(img, model=seg_model):
57
+ # pil_image = img.convert('RGB')
58
+ # open_cv_image = np.array(pil_image)
59
+ # img = open_cv_image[:, :, ::-1].copy()
60
  # # img = cv2.imread("./003e2c95d.jpg")
61
  img = img[::IMG_SCALING[0], ::IMG_SCALING[1]]
62
  img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
 
64
  img = tf.expand_dims(img, axis=0)
65
  pred = model.predict(img)
66
  pred = np.squeeze(pred, axis=0)
67
+ pil_img = Image.fromarray((x * 255).astype(np.uint8))
68
+ # pil_img = Image.fromarray(pred, 'RGB')
69
  # im = Image.fromarray((pred * 255).astype(np.uint8))
70
  # img_bytes = pred.tobytes()
71
  # nparr = np.frombuffer(img_bytes, np.byte)
 
78
  # css_code='body{background-image:url("file=wave.mp4");}'
79
 
80
  gr.Interface(fn=gen_pred,
81
+ inputs=[gr.Image(type='numpy')],
82
  outputs=gr.Image(type='numpy'),
83
  title=title,
84
  examples=[["003e2c95d.jpg"], ["003b50a15.jpg"], ["003b48a9e.jpg"], ["0038cbe45.jpg"], ["00371aa92.jpg"]],