Spaces:
Runtime error
Runtime error
| import logging | |
| import os | |
| import tensorflow as tf | |
| def set_tf_loglevel(level): | |
| if level >= logging.FATAL: | |
| os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' | |
| if level >= logging.ERROR: | |
| os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' | |
| if level >= logging.WARNING: | |
| os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1' | |
| else: | |
| os.environ['TF_CPP_MIN_LOG_LEVEL'] = '0' | |
| logging.getLogger('tensorflow').setLevel(level) | |
| def img_to_tensor(path): | |
| ''' | |
| convert images to tensor | |
| args: | |
| path : image file path | |
| ''' | |
| img = tf.keras.utils.load_img( | |
| path, | |
| color_mode="rgb", | |
| target_size=(224, 224), | |
| interpolation="nearest", | |
| ) | |
| img_arr = tf.keras.utils.img_to_array(img, data_format=None, dtype=None) | |
| img = tf.expand_dims(img_arr, 0) | |
| return img | |