为了账号安全,请及时绑定邮箱和手机立即绑定

张量流值错误:无法为张量 u'InputData/X:0' 提供形状值 (96, 50, 50)

张量流值错误:无法为张量 u'InputData/X:0' 提供形状值 (96, 50, 50)

ITMISS 2022-09-20 15:56:21
我是张量流和蟒蛇的新手。我正在尝试使用CNN运行肺癌检测代码。脚本如下:我正在尝试训练 CNN 模型。当我在训练时使用时,我遇到错误model.fit    from tflearn.layers.core import input_data, dropout, fully_connectedfrom tflearn.layers.conv import conv_2d, max_pool_2dfrom tflearn.layers.estimator import regressionfrom tflearn.data_preprocessing import ImagePreprocessingfrom tflearn.data_augmentation import ImageAugmentationimg_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
查看完整描述

1 回答

?
MMTTMM

TA贡献1869条经验 获得超4个赞

该模型期望直径为 4 的张量。您必须向训练数据添加第四个维度。用

X_train_images = np.expand_dims(X_train_images, axis=-1)

扩展尺寸和 np.挤压以减小尺寸


查看完整回答
反对 回复 2022-09-20
  • 1 回答
  • 0 关注
  • 81 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号