aje6 commited on
Commit
1cb4ea2
·
verified ·
1 Parent(s): fcdb808

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -13
app.py CHANGED
@@ -244,32 +244,27 @@ def predict(image):
244
  input_name = model.get_inputs()[0].name
245
  input_shape = model.get_inputs()[0].shape
246
 
247
- print("start", image.shape) #start (720, 1280, 3)
248
-
249
-
250
  # Resize the image to the model's input shape
251
  image = cv2.resize(image, (input_shape[2], input_shape[3]))
252
-
253
- print("after resize", image.shape) # after resize (640, 640, 3)
254
-
255
  image = image.reshape(3, 640, 640)
256
 
257
- print("after reshape", image.shape) # after reshape
258
-
259
  # Convert the image to a numpy array and add a batch dimension
260
  if len(input_shape) == 4 and input_shape[0] == 1:
261
  image = np.expand_dims(image, axis=0)
262
 
263
  image = image.astype(np.float32) # after expands/astype (1, 640, 640, 3)
264
 
265
- print("after expands/astype", image.shape)
266
-
 
 
 
267
  # Perform inference
268
  output = model.run(None, {input_name: image})
269
- print(type(output))
270
- print(output)
271
 
272
- return image
273
 
274
  # Gradio interface
275
  demo = gr.Interface(
 
244
  input_name = model.get_inputs()[0].name
245
  input_shape = model.get_inputs()[0].shape
246
 
 
 
 
247
  # Resize the image to the model's input shape
248
  image = cv2.resize(image, (input_shape[2], input_shape[3]))
 
 
 
249
  image = image.reshape(3, 640, 640)
250
 
 
 
251
  # Convert the image to a numpy array and add a batch dimension
252
  if len(input_shape) == 4 and input_shape[0] == 1:
253
  image = np.expand_dims(image, axis=0)
254
 
255
  image = image.astype(np.float32) # after expands/astype (1, 640, 640, 3)
256
 
257
+ # Normalize the image
258
+ mean = [0.485, 0.456, 0.406]
259
+ std = [0.229, 0.224, 0.225]
260
+ image = (image / 255.0 - mean)/std
261
+
262
  # Perform inference
263
  output = model.run(None, {input_name: image})
264
+ # print(type(output))
265
+ # print(output)
266
 
267
+ return output
268
 
269
  # Gradio interface
270
  demo = gr.Interface(