拟合3D UNet模型时出错:预期会看到1个阵列,但得到了以下2个阵列的列表。适合模型

我怀疑由于返回的数组数量,我的数据生成正在给我带来错误。 ValueError:检查模型目标时出错:传递给模型的Numpy数组列表不是大小预期的模型。预计会看到1个阵列,但获得了以下2个阵列的列表 以下是数据生成器代码:

class DataGenerator(Sequence):
'Generates data for Keras'
def __init__(self,list_IDs,im_path,label_path,batch_size=2,dim=(256,256,120),augment=False,n_channels=2,n_classes=3,shuffle=True):
    'Initialization'
    self.dim = dim
    self.batch_size = batch_size
    self.label_path = label_path
    self.list_IDs = list_IDs
    self.augment = augment
    self.n_channels=n_channels
    self.n_classes = n_classes
    self.shuffle = shuffle
    self.on_epoch_end()

def __len__(self):
    'Denotes the number of batches per epoch'
    return int(np.floor(len(self.list_IDs) / self.batch_size))


def on_epoch_end(self):
    'Updates indexes after each epoch'
    self.indexes = np.arange(len(self.list_IDs))
    if self.shuffle == True:
        np.random.shuffle(self.indexes)


def __getitem__(self,index):
    'Generate one batch of data'
    # Generate indexes of the batch
    indexes = self.indexes[index*self.batch_size:(index+1)*self.batch_size]

    # Find list of IDs
    list_IDs_temp = [self.list_IDs[k] for k in indexes]

    # Generate data
    X,y = self.__data_generation(list_IDs_temp)

    return X,y

def __data_generation(self,list_IDs_temp):
    X = np.empty([self.batch_size,self.n_channels,*self.dim])
    Y = np.empty([self.batch_size,3,*self.dim])
    X_ = []
    y_ = []

    # Generate data
    for i,ID in enumerate(list_IDs_temp):
        img = nib.load(im_path + ID).get_data() 
        mask = nib.load(label_path + ID).get_data() 
        mask = np.clip(mask,255)
        cmask = (mask * 1. / 255)
        out = cmask
        X_.append(img)
        y_.append(out)
    X = np.expand_dims(X_,-1)
    y = np.expand_dims(y_,-1)
    y = np.concatenate((1 - y,y),-1)
    y = np.array(y)
    print ('### Dataset loaded')
    print ('\t{}'.format(im_path))
    print ('\t{}\t{}'.format(X.shape,y.shape))
    print ('\tX:{:.1f}-{:.1f}\ty:{:.1f}-{:.1f}\n'.format(X.min(),X.max(),y.min(),y.max()))
    return X,y

在我的培训课程中,内容如下:

    params = {'dim': (256,'batch_size': 2,'im_path': im_path,'label_path': label_path,'n_classes': 2,'augment': False,'n_channels':2,'shuffle': True
                 }
        model = build_model() 
        model.compile(optimizer='adam',loss='binary_crossentropy',metrics=['binary_accuracy'])
        cb_1=keras.callbacks.EarlyStopping(monitor='val_loss',min_delta=0,patience=2,verbose=1,mode='auto')
        cb_2=keras.callbacks.ModelCheckpoint(filepath="model.{epoch:03d}.hdf5",monitor='val_loss',verbose=0,save_best_only=True,save_weights_only=False,mode='auto',period=1)

        results = model.fit(X,y,epochs=1,validation_split=0.2,callbacks=[cb_1,cb_2])
huanhuanelsie 回答:拟合3D UNet模型时出错:预期会看到1个阵列,但得到了以下2个阵列的列表。适合模型

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3162660.html

大家都在问