File size: 831 Bytes
9358e26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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