简体   繁体   中英

AttributeError: 'Tensor' object has no attribute 'read'

im going to build a bicubic image in a function and then i want to use it in one of my layers in API model,i see this error,how can i solve it ? thank u !!

def model_bicubic(image):
    image = Image.open(image, mode = 'r')
    width, height = image.size
    image_bicubic = image.resize((width*2, height*2), Image.BICUBIC)

    return image_bicubic

You can try this in the following way:

def load_image(img_path):
    img = tf.io.read_file(img_path)
    img = tf.io.decode_jpeg(img, channels = 3)
    img = tf.image.resize(img, size = (width, height), method = 'bicubic')
    img = img / 255.0
    return img

Worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM