Ошибка: попытка преобразовать значение PIL в тензор.Python

Программы на Python
Anonymous
Ошибка: попытка преобразовать значение PIL в тензор.

Сообщение Anonymous »

Я попробовал запустить этот код:
import tensorflow as tf
from tensorflow import keras
from keras.models import load_model
import streamlit as st
import numpy as np

st.header('Image Classification Model')
model = load_model('C:\\Users\\ajit7\\OneDrive\\Documents\\Major Project\\Image_classify.keras')
data_cat = ['WithMask', 'WithoutMask']
img_height = 224
img_width = 224
image =st.text_input('Enter Image name','C:\\Users\\ajit7\\OneDrive\\Documents\\Major Project\\gayatri-malhotra-26SGAduvONc-unsplash.png')

image_load = tf.keras.utils.load_img(image, target_size=(img_height,img_width))
img_arr = tf.keras.utils.array_to_img(image_load)
img_bat=tf.expand_dims(img_arr,0)

predict = model.predict(img_bat)

score = tf.nn.softmax(predict)
st.image(image, width=200)
st.write( data_cat[np.argmax(score)])
st.write('With accuracy of ' + str(np.max(score)*100))`

Я ожидал получить информацию на основе прогноза используемой мной модели, но вместо этого получил следующее:
ValueError: Attempt to convert a value () with an unsupported type () to a Tensor.
Traceback:
File "C:\ProgramData\anaconda3\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 584, in _run_script
exec(code, module.__dict__)
File "C:\Users\ajit7\OneDrive\Documents\Major Project\app1.py", line 17, in
img_bat=tf.expand_dims(img_arr,0)
File "C:\ProgramData\anaconda3\lib\site-packages\tensorflow\python\util\traceback_utils.py", line 153, in error_handler
raise e.with_traceback(filtered_tb) from None
File "C:\ProgramData\anaconda3\lib\site-packages\tensorflow\python\framework\constant_op.py", line 102, in convert_to_eager_tensor
return ops.EagerTensor(value, ctx.device_name, dtype)


Подробнее здесь: https://stackoverflow.com/questions/783 ... o-a-tensor

Вернуться в «Python»