我是張量流和蟒蛇的新手。我正在嘗試使用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.擠壓以減小尺寸
添加回答
舉報
0/150
提交
取消