【问题标题】:Unable to create dataset for image segmentation keras无法为图像分割 keras 创建数据集
【发布时间】:2018-12-09 10:21:44
【问题描述】:

我有一个自定义数据集,其中包含 1100 个跨 RGB 通道的视网膜图像及其相应的灰度蒙版,分辨率为 1500x1500。工作是从这些图像中提取视盘。我一直在尝试从这些图像中创建训练集,以便可以将其放入 u-net 模型中。我已经使用 opencv 将所有图像的大小调整为 256x256 分辨率,并创建了这些图像的 numpy 数组。但是,当我将这些数据拟合到模型中时,无论我增加多少个 epoch,我的准确度都不会大于 1。我也试过骰子系数和损失函数。他们给出的值也大于 1。我想知道问题出在训练数据创建还是模型中。 下面是我用于创建训练集的代码。

train_data='train_image_folder'
label_data="mask_image_folder"
def training():
    train_images=[]
    for i in tqdm(os.listdir(train_data)):
        path=os.path.join(train_data,i)
        img=cv2.imread(path,-1)
        img=cv2.resize(img,(256,256))
        train_images.append(np.array(img))
    return train_images
training_images=training()
train_data=np.array([training_images]).reshape(-1,256,256,3)
def label():
    label_images=[]
    for i in tqdm(os.listdir(label_data)):
        path=os.path.join(label_data,i)
        img=cv2.imread(path,0)
        img=cv2.resize(img,(256,256))
        label_images.append(np.array(img))
    return label_images
label_images=label()
label_data=np.array([label_images]).reshape(-1,256,256,1)

下面是编译拟合的代码

model.compile(loss="binary_crossentropy", optimizer="adam", metrics=["accuracy","binary_crossentropy",dice_coef])
model.fit(train_data,label_data,epochs=50,batch_size=20)

以及对应的骰子系数函数

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)

我不知道我做错了什么。任何帮助将不胜感激

【问题讨论】:

    标签: python tensorflow keras conv-neural-network image-segmentation


    【解决方案1】:

    我可以请你把你的代码(创建模型)? 你是测试 SGD 还是改变学习率?

    from keras.optimizers import Adam, SGD
    ...
    ...
    model.compile(loss="categorical_crossentropy", # Change to categorical
    optimizer=Adam(lr = .1), # For exam, or use SGD(lr = .1) and change learning rate and momentum
        metrics=["accuracy",dice_coef])
    

    请测试这部分代码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-12
      • 2021-05-20
      • 2018-05-12
      • 2018-05-18
      • 2016-11-04
      • 1970-01-01
      • 2018-07-21
      • 1970-01-01
      相关资源
      最近更新 更多