我是keras和python的新手。我只是想知道如何将2d形输入转换为3d形输入。 我的2d输入数据是192x192和3个图像。 所以,使用这个2d形状输入数据,我想制作192x192x3输入形状。 我的代码如下。
from __future__ import print_function
import os
from skimage.transform import resize
from skimage.io import imsave
import numpy as np
from keras.models import Model, load_model
from keras.layers import Input, concatenate, Conv2D, MaxPooling2D, Conv2DTranspose, Dropout, Conv3D, MaxPooling3D
from keras.optimizers import Adam
from keras.callbacks import ModelCheckpoint
from keras import backend as K
from data import load_train_data, load_test_data #, load_test_validation_data
import matplotlib.pyplot as plt
from keras.preprocessing.image import ImageDataGenerator
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
K.set_image_data_format('channels_last')
image_rows = 192
image_cols = 192
total = 482
img_rows = 192 # 96
img_cols = 192 # 96
smooth = 1.
def dice_coef(y_true, y_pred):
y_true_f = K.flatten(y_true)
y_pred_f = K.flatten(y_pred)
intersection = K.sum(y_true_f * y_pred_f)
return (2. * intersection + smooth) / (K.sum(y_true_f) + K.sum(y_pred_f) + smooth)
def dice_coef_loss(y_true, y_pred):
return -dice_coef(y_true, y_pred)
def get_unet():
## layer #1
input1 = Input((img_rows, img_cols, 1), name='input1') ## (?, 192, 192,1)
input2 = Input((img_rows, img_cols, 1), name='input2') ## (?, 192, 192,1)
input3 = Input((img_rows, img_cols, 1), name='input3') ## (?, 192, 192,1)
inputs = np.ndarray((total, img_rows, img_cols, 3), dtype=np.float32)
inputs[:, :, :, 0] = input1
inputs[:, :, :, 1] = input2
inputs[:, :, :, 2] = input3
conv1_1 = Conv3D(32, (3, 3, 3), activation='relu', padding='same')(inputs)
conv1_1 = Conv3D(32, (3, 3, 3), activation='relu', padding='same')(conv1_1)
pool1_1 = MaxPooling3D(pool_size=(2, 2, 1))(conv1_1)
drop1_1 = Dropout(0.2)(pool1_1)
......
此行发生错误。
inputs[:, :, :, 0] = input1
错误信息如下。
输入[:,:,:,0] = input1 ValueError:使用序列设置数组元素。
是否有人可以建议我将三个2d输入组合到Keras的3d形输入中?感谢。