【发布时间】:2020-07-11 20:59:21
【问题描述】:
我是 TensorFlow 和 python 的新手。我正在尝试使用 CNN 运行用于肺癌检测的代码。这是脚本:我正在尝试训练一个 CNN 模型。当我在训练时使用model.fit 时出现错误
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.estimator import regression
from tflearn.data_preprocessing import ImagePreprocessing
from tflearn.data_augmentation import ImageAugmentation
img_prep = ImagePreprocessing()
img_prep.add_featurewise_zero_center()
img_prep.add_featurewise_stdnorm()
img_aug = ImageAugmentation()
img_aug.add_random_flip_leftright()
img_aug.add_random_rotation(max_angle=25.)
img_aug.add_random_blur(sigma_max=3.)
network = input_data(shape=[None, 50, 50, 1],
data_preprocessing=img_prep,
data_augmentation=img_aug)
network = conv_2d(network, 50, 3, activation='relu')
network = max_pool_2d(network, 2)
network = conv_2d(network, 64, 3, activation='relu')
network = conv_2d(network, 64, 3, activation='relu')
network = max_pool_2d(network, 2)
network = fully_connected(network, 512, activation='relu')
network = dropout(network, 0.5)
network = fully_connected(network, 2, activation='softmax')
network = regression(network, optimizer='adam',
loss='categorical_crossentropy',
learning_rate=0.001)
model = tflearn.DNN(network, tensorboard_verbose=0, checkpoint_path='nodule-classifier.tfl.ckpt')
model.fit(X_train_images, Y_train_labels, n_epoch=100, shuffle=True, validation_set=(X_val_images, Y_val_labels),
show_metric=True, batch_size=96, snapshot_epoch=True,
run_id='noduleclassifier')
model.save("nodule-classifier.tfl")
print("Network trained and saved as nodule-classifier.tfl!")
我正在尝试训练一个 CNN 模型。当我在训练时使用model.fit 时出现错误 -->
ValueErrorTraceback (most recent call last)
<ipython-input-60-e6a88471dbf1> in <module>()
5 model.fit(X_train_images, Y_train_labels, n_epoch=100, shuffle=True, validation_set=(X_val_images, Y_val_labels),
6 show_metric=True, batch_size=96, snapshot_epoch=True,
----> 7 run_id='noduleclassifier')
8
9 # Save model when training is complete to a file
-----------------------------------------------------------------------------
/tensorflow-1.15.2/python2.7/tensorflow_core/python/client/session.pyc in _run(self, handle, fetches, feed_dict, options, run_metadata)
1154 'Cannot feed value of shape %r for Tensor %r, '
1155 'which has shape %r' %
-> 1156 (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))
1157 if not self.graph.is_feedable(subfeed_t):
1158 raise ValueError('Tensor %s may not be fed.' % subfeed_t)
ValueError: Cannot feed value of shape (96, 50, 50) for Tensor u'InputData/X:0', which has shape '(?, 50, 50, 1)'
链接到原始代码 --> link
谁能帮我解决这个问题?
【问题讨论】:
-
您好!欢迎来到 SO!请转至how to ask
-
只看标题,
numpy.squeeze可以帮助您摆脱形状 1 的额外维度。 -
你能解释一下吗
-
哪部分不明白?
-
如何使用'numpy.squeeze'
标签: python deep-learning google-colaboratory conv-neural-network