jaekookang commited on
Commit
57064d0
β€’
1 Parent(s): c31a89f

add resize option

Browse files
Files changed (1) hide show
  1. gradio_artist_classifier.py +8 -5
gradio_artist_classifier.py CHANGED
@@ -13,7 +13,9 @@ import seaborn as sns
13
  import io
14
  import json
15
  import numpy as np
 
16
  import skimage.io
 
17
  from loguru import logger
18
  from huggingface_hub import from_pretrained_keras
19
  import gradio as gr
@@ -49,14 +51,15 @@ def load_image_as_array(image_file):
49
  img = img[..., :-1]
50
  return img
51
 
52
- def load_image_as_tensor(image_file):
53
- img = tf.io.read_file(image_file)
54
- img = tf.io.decode_jpeg(img, channels=3)
55
- return img
 
56
 
57
  def predict(input_image):
58
  img_3d_array = load_image_as_array(input_image)
59
- # img_4d_tensor = load_image_as_tensor(input_image)
60
  img_4d_array = img_3d_array[np.newaxis,...]
61
  logger.info(f'--- {input_image} loaded')
62
 
 
13
  import io
14
  import json
15
  import numpy as np
16
+ import skimage
17
  import skimage.io
18
+ from skimage.transform import resize
19
  from loguru import logger
20
  from huggingface_hub import from_pretrained_keras
21
  import gradio as gr
 
51
  img = img[..., :-1]
52
  return img
53
 
54
+ def resize_image(img_array, width, height):
55
+ img_resized = resize(img_array, (height, width),
56
+ anti_aliasing=True,
57
+ preserve_range=False)
58
+ return skimage.img_as_ubyte(img_resized)
59
 
60
  def predict(input_image):
61
  img_3d_array = load_image_as_array(input_image)
62
+ img_3d_array = resize_image(img_3d_array)
63
  img_4d_array = img_3d_array[np.newaxis,...]
64
  logger.info(f'--- {input_image} loaded')
65