Spaces:
Runtime error
Runtime error
Upload helper.py
Browse files
helper.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import logging
|
2 |
+
import os
|
3 |
+
import tensorflow as tf
|
4 |
+
|
5 |
+
|
6 |
+
def set_tf_loglevel(level):
|
7 |
+
if level >= logging.FATAL:
|
8 |
+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
|
9 |
+
if level >= logging.ERROR:
|
10 |
+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
11 |
+
if level >= logging.WARNING:
|
12 |
+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1'
|
13 |
+
else:
|
14 |
+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '0'
|
15 |
+
logging.getLogger('tensorflow').setLevel(level)
|
16 |
+
|
17 |
+
|
18 |
+
def img_to_tensor(path):
|
19 |
+
'''
|
20 |
+
convert images to tensor
|
21 |
+
args:
|
22 |
+
path : image file path
|
23 |
+
'''
|
24 |
+
|
25 |
+
img = tf.keras.utils.load_img(
|
26 |
+
path,
|
27 |
+
color_mode="rgb",
|
28 |
+
target_size=(224, 224),
|
29 |
+
interpolation="nearest",
|
30 |
+
)
|
31 |
+
img_arr = tf.keras.utils.img_to_array(img, data_format=None, dtype=None)
|
32 |
+
img = tf.expand_dims(img_arr, 0)
|
33 |
+
return img
|