I'd like to set up a diagnostic imaging program, but I get the following error.
I'm using google collateral and I'm trying to upload some of them from kaggle's Chest X-Ray Images (Pneumonia) dataset to google drive for use.
The image is gray scale.
In the video I used as a reference, I used a color image, so it may be related, but I don't know how to fix it.I would appreciate it if someone could tell me.
error message
------------------------------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-97-c83072b43715>in<module>()
24
25
--- > 26x_train=np.array(x_train)/255.0
27 y_train=np.array(y_train)
28 x_test = np.array(x_test)/255.0
ValueError: could not broadcast input array from shape(100,100,1) into shape(100,100)
source code
import numpy as np
import tensorflow as tf
from tensorflow import keras
import glob
x_train=[ ]
y_train=[]
x_test=[ ]
y_test=[ ]
for inglob.glob("/content/drive/MyDrive/kaggle/image/*/*.jpeg"):
img_data=tf.io.read_file(f)
img_data=tf.io.decode_jpeg(img_data)
img_data=tf.image.resize(img_data,(100,100))
if f.split("/")[6]=="train":
x_train.append(img_data)
y_train.append(int(f.split("/")[7].split("_")[0]))
eliff.split("/")[6]=="test":
x_test.append(img_data)
y_test.append(int(f.split("/")[7].split("_")[0]))
x_train=np.array(x_train)/255.0
y_train=np.array(y_train)
x_test=np.array(x_test)/255.0
y_test=np.array(y_test)
I found a similar case.
ValueError: could not broadcast input array from shape(224,224,3) into shape(224,224)
The same error appears when you do the following:
a=np.random.rand(100,100,1)
b=np.random.rand(100,100)
c=[a,b]
c=np.array(c)
I can't say for sure until I check the original file, but I think it contains different sizes of img_data.
© 2024 OneMinuteCode. All rights reserved.