简体   繁体   English

ValueError:检查输入时出错:预期density_11_input具有3维,但数组的形状为(0,1)

[英]ValueError: Error when checking input: expected dense_11_input to have 3 dimensions, but got array with shape (0, 1)

I am new in machine learning and python and I try to make classification whether a patient cancer or not. 我是机器学习和python的新手,无论是否患癌症,我都会尝试进行分类。 I found a piece of code from https://github.com/fahomid/ML-Tensorflow-Medical-Image/blob/master/tensorflow-model.py I have a small dataset. 我从https://github.com/fahomid/ML-Tensorflow-Medical-Image/blob/master/tensorflow-model.py找到了一段代码。我有一个小的数据集。 Training and test set have two patient directories that have dicom files just for trying. 训练和测试集有两个患者目录,其中包含dicom文件供尝试使用。 The code is as following; 代码如下:

import keras
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten
from keras.layers import Conv2D, MaxPooling2D
import os
import pydicom
import numpy as np
import PIL

# Generate data from dicom file
dataset = [];
labels = [];
for root, dirs, files in os.walk("training_data/Cancer"):
    for file in files:
        if file.endswith(".dcm"):
            ds = pydicom.dcmread(os.path.join(root, file))
            dataset.append(ds.pixel_array)
            labels.append(1);

for root, dirs, files in os.walk("training_data/Normal"):
   for file in files:
        if file.endswith(".dcm"):
            ds = pydicom.dcmread(os.path.join(root, file))
            dataset.append(ds.pixel_array)
            labels.append(0)


dataset_size = len(dataset)
dataset = np.asarray(dataset)
labels = np.asarray(labels)

# create model
model = Sequential()
model.add(Dense(32, activation='tanh', input_shape=(512, 512)))
model.add(Flatten())
model.add(Dense(1, activation='sigmoid'))
model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics= 
['accuracy'])
model.fit(dataset, labels, epochs=10, shuffle=True, batch_size=32)

# serialize model to JSON
model_json = model.to_json()
with open("model.json", "w") as json_file:
    json_file.write(model_json)
# serialize weights to HDF5
model.save_weights("model.h5")
print("\n\nModel saved to disk\n\n")
model.summary()

The line of error message is as following; 错误消息行如下:

model.fit(dataset, labels, epochs=10, shuffle=True, batch_size=32) model.fit(数据集,标签,时期= 10,随机播放= True,batch_size = 32)

ValueError: Error when checking input: expected dense_11_input to have 3 dimensions, but got array with shape (0, 1) ValueError:检查输入时出错:预期density_11_input具有3维,但数组的形状为(0,1)

Thanks for your help. 谢谢你的帮助。

The following section of your code looks for files (with .dcm extension) containing the data for Cancer and Normal person. 代码的以下部分查找包含癌症正常人数据的文件(扩展名为.dcm )。 It does NOT find any, So it returns nothing. 没有找到任何,所以它没有返回。

# Generate data from dicom file
dataset = [];
labels = [];
for root, dirs, files in os.walk("training_data/Cancer"):
    for file in files:
        if file.endswith(".dcm"):
            ds = pydicom.dcmread(os.path.join(root, file))
            dataset.append(ds.pixel_array)
            labels.append(1);

for root, dirs, files in os.walk("training_data/Normal"):
   for file in files:
        if file.endswith(".dcm"):
            ds = pydicom.dcmread(os.path.join(root, file))
            dataset.append(ds.pixel_array)
            labels.append(0)

So the value of dataset variable is 0 , and labels variable is 1 . 因此, dataset变量的值为0labels变量为1 And when the model.fit method is called, it expects the input to be 3 dimensions with the shape of (512, 512) , but it only gets the input with the shape of (0, 1) . 并且当调用model.fit方法时,它期望输入为(512, 512)形状的3维,但仅获得形状为(0, 1)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ValueError:检查输入时出错:预期density_6_input具有3维,但数组的形状 - ValueError: Error when checking input: expected dense_6_input to have 3 dimensions, but got array with shape ValueError:检查输入时出错:预期dense_input有2维,但得到形状为(1,1,2)的数组 - ValueError: Error when checking input: expected dense_input to have 2 dimensions, but got array with shape (1, 1, 2) ValueError:检查输入时出错:预期density_151_input具有3维,但数组的形状为(2,2100) - ValueError: Error when checking input: expected dense_151_input to have 3 dimensions, but got array with shape (2, 2100) ValueError:检查输入时出错:预期的dense_input有2维,但得到的数组形状为(1、1、15) - ValueError: Error when checking input: expected dense_input to have 2 dimensions, but got array with shape (1, 1, 15) ValueError:检查时出错:预期density_1_input具有2维,但数组的形状为(1,16,16,512) - ValueError: Error when checking : expected dense_1_input to have 2 dimensions, but got array with shape (1, 16, 16, 512) ValueError:检查输入时出错:预期density_16_input具有2维,但数组的形状为(60000,28,28) - ValueError: Error when checking input: expected dense_16_input to have 2 dimensions, but got array with shape (60000, 28, 28) 我不断收到此错误“ValueError:检查输入时出错:预期的dense_8_input有2维,但得到的数组形状为(705,66,1)” - I keep getting this error “ValueError: Error when checking input: expected dense_8_input to have 2 dimensions, but got array with shape (705, 66, 1)” ValueError:检查输入时出错:预期density_1_input具有2维,但数组的形状为(60000,28,28) - ValueError: Error when checking input: expected dense_1_input to have 2 dimensions, but got array with shape (60000, 28, 28) ValueError:检查输入时出错:预期dense_10_input有2维,但得到的数组形状为(60000、28、28) - ValueError: Error when checking input: expected dense_10_input to have 2 dimensions, but got array with shape (60000, 28, 28) ValueError:检查输入时出错:预期dense_1_input 具有形状(9,) 但得到形状为(1,) 的数组 - ValueError: Error when checking input: expected dense_1_input to have shape (9,) but got array with shape (1,)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM