Conner commited on
Commit
320edad
·
1 Parent(s): dd27c16

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -16
app.py CHANGED
@@ -8,30 +8,26 @@ def greet(name):
8
  return "Hello " + name + "!!"
9
 
10
  def predict(img):
11
-
12
- # Load the model
13
  model = load_model('keras_model.h5')
14
-
15
- # Create the array of the right shape to feed into the keras model
16
- # The 'length' or number of images you can put into the array is
17
- # determined by the first position in the shape tuple, in this case 1.
18
  data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
19
- # Replace this with the path to your image
20
  image = img
21
- # image = Image.open('<IMAGE_PATH>')
22
- #resize the image to a 224x224 with the same strategy as in TM2:
23
- #resizing the image to be at least 224x224 and then cropping from the center
24
  size = (224, 224)
25
  image = ImageOps.fit(image, size, Image.ANTIALIAS)
26
-
27
- #turn the image into a numpy array
28
  image_array = np.asarray(image)
29
- # Normalize the image
30
  normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
31
- # Load the image into the array
32
  data[0] = normalized_image_array
33
-
34
- # run the inference
35
  prediction = model.predict(data)
36
  gr.outputs.Label = open(labels.txt)
37
  return prediction
 
8
  return "Hello " + name + "!!"
9
 
10
  def predict(img):
11
+ # Load the model
 
12
  model = load_model('keras_model.h5')
13
+ # Create the array of the right shape to feed into the keras model
14
+ # The 'length' or number of images you can put into the array is
15
+ # determined by the first position in the shape tuple, in this case 1.
 
16
  data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)
17
+ # Replace this with the path to your image
18
  image = img
19
+ # image = Image.open('<IMAGE_PATH>')
20
+ #resize the image to a 224x224 with the same strategy as in TM2:
21
+ #resizing the image to be at least 224x224 and then cropping from the center
22
  size = (224, 224)
23
  image = ImageOps.fit(image, size, Image.ANTIALIAS)
24
+ #turn the image into a numpy array
 
25
  image_array = np.asarray(image)
26
+ # Normalize the image
27
  normalized_image_array = (image_array.astype(np.float32) / 127.0) - 1
28
+ # Load the image into the array
29
  data[0] = normalized_image_array
30
+ # run the inference
 
31
  prediction = model.predict(data)
32
  gr.outputs.Label = open(labels.txt)
33
  return prediction