首先,我对这些话题还是一个新手。我的神经网络在训练集和验证集上将所有事物分类为人或背景。训练集是VOC2011。
https://github.com/JihongJu/keras-fcn
#Defining modelfrom keras_fcn import FCNfcn_vgg16 = FCN(input_shape=(500, 500, 3), classes=21)fcn_vgg16.load_weights('fcn_vgg16_weights.h5')#Preprocessing to imagefrom keras.preprocessing import imagefrom keras.applications.vgg16 import preprocess_inputimport numpy as npimg_path = 'catdog2.jpg'img1 = image.load_img(img_path, target_size=(500, 500))x = image.img_to_array(img1)x = np.expand_dims(x, axis=0)#x = preprocess_input(x)predicted = fcn_vgg16.predict(x)predicted = np.squeeze(predicted, axis=0)#I may have completely misunderstood the visualization partcolor_list = {0:[176, 23, 31], 1:[220, 20, 60], 2:[139, 71, 93], 3:[0, 9, 236], 3:[255, 20, 147], 4:[139, 0, 139], 5:[0, 0, 255], 6:[202, 225, 255], 7:[30, 144, 255], 8:[240, 248, 255], 9:[0, 245, 255], 10:[0, 199, 140], 11:[0, 255, 127], 12:[139, 131, 134], 13:[255, 255, 0], 14:[255,165, 0], 15:[255, 153, 18], 16:[255, 69, 0], 17:[255, 0, 0], 18:[0, 0, 0], 19:[219,219, 219], 20:[0, 245, 255],255:[0, 0, 205]}#*15:[255, 153, 18] => Orange*"""{0: 'background', 1: 'aeroplane', 2: 'bicycle', 3: 'bird', 4: 'boat', 5: 'bottle', 6: 'bus', 7: 'car', 8: 'cat', 9: 'chair', 10: 'cow', 11: 'diningtable', 12: 'dog', 13: 'horse', 14: 'motorbike', 15: 'person', 16: 'potted-plant', 17: 'sheep', 18: 'sofa', 19: 'train', 20: 'tv/monitor', 255: 'ambigious'} """#http://warmspringwinds.github.io/tensorflow/tf-slim/2017/01/23/fully-convolutional-networks-(fcns)-for-image-segmentation/import scipy.misc as smp#Create a 500x500x3 array of 8 bit unsigned integersdata = np.zeros((500, 500, 3), dtype=np.uint8)for i in range(500): for j in range(500): data[i][j] = color_list[np.argmax(predicted[i][j])]img2 = smp.toimage(data)import matplotlib.pyplot as pltf, (ax1, ax2) = plt.subplots(1, 2, sharey=True)ax1.imshow(np.squeeze(img1, axis=0))ax2.imshow(img2)plt.show()
这是否是一种局部最小值(或鞍点?),预测所有事物为背景(最常见的标签)?
原因是什么,您有什么想法?另外,语义分割的可视化是否有合适的方法?
我猜训练过程中出了问题。如果存在过拟合,损失值一直下降,为什么训练数据的结果仍然相同?
回答:
关于将所有事物分类为背景的问题。
我假设提供的图像是从训练的早期到后期的进展(可能来自训练集)。
一些建议:
-
尝试使用加权成本函数进行初步训练,权重与数据集中标签的比例成反比。这应该能让它克服由于先验力量导致的任何最小值/鞍点。
-
尝试调整正则化参数。