khengkok commited on
Commit
fcb2a5c
1 Parent(s): f9fc222
Files changed (1) hide show
  1. app.py +5 -19
app.py CHANGED
@@ -9,33 +9,19 @@ from object_detection.utils import ops as utils_op
9
  import tarfile
10
  import wget
11
  import gradio as gr
12
- import PIL
13
- import gradio as gr
14
 
15
  PATH_TO_LABELS = 'data/label_map.pbtxt'
16
  category_index = label_map_util.create_category_index_from_labelmap(PATH_TO_LABELS, use_display_name=True)
17
 
18
  def pil_image_as_numpy_array(pilimg):
19
 
20
- (im_width, im_height) = pilimg.size
 
 
21
 
22
- return np.array(pilimg.getdata())[:,:3].reshape(
23
- (1, im_height, im_width, 3)).astype(np.uint8)
24
-
25
-
26
  def load_image_into_numpy_array(path):
27
- """Load an image from file into a numpy array.
28
-
29
- Puts image into numpy array to feed into tensorflow graph.
30
- Note that by convention we put it into a numpy array with shape
31
- (height, width, channels), where channels=3 for RGB.
32
-
33
- Args:
34
- path: the file path to the image
35
-
36
- Returns:
37
- uint8 numpy array with shape (img_height, img_width, 3)
38
- """
39
  image = None
40
  image_data = tf.io.gfile.GFile(path, 'rb').read()
41
  image = Image.open(BytesIO(image_data))
 
9
  import tarfile
10
  import wget
11
  import gradio as gr
12
+
 
13
 
14
  PATH_TO_LABELS = 'data/label_map.pbtxt'
15
  category_index = label_map_util.create_category_index_from_labelmap(PATH_TO_LABELS, use_display_name=True)
16
 
17
  def pil_image_as_numpy_array(pilimg):
18
 
19
+ img_array = tf.keras.utils.img_to_array(pilimg)
20
+ img_array = np.expand_dims(img_array, axis=0)
21
+ return img_array
22
 
 
 
 
 
23
  def load_image_into_numpy_array(path):
24
+
 
 
 
 
 
 
 
 
 
 
 
25
  image = None
26
  image_data = tf.io.gfile.GFile(path, 'rb').read()
27
  image = Image.open(BytesIO(image_data))