Why does my neural net identify everything as person or background for a semantic segmentation task?

Viewed 535

Firstly, I am newbie to these topics. My neural network classifies everything as person or background on both training and validation sets. Training set is VOC2011.

https://github.com/JihongJu/keras-fcn

#Defining model
from keras_fcn import FCN
fcn_vgg16 = FCN(input_shape=(500, 500, 3), classes=21)
fcn_vgg16.load_weights('fcn_vgg16_weights.h5')


#Preprocessing to image
from keras.preprocessing import image
from keras.applications.vgg16 import preprocess_input
import numpy as np
​
img_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 part
color_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 integers
data = 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 plt
f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
ax1.imshow(np.squeeze(img1, axis=0))
ax2.imshow(img2)
plt.show()

Here is the result (orange means person)

Without preprocessing to image

With human and non human segmentation

100 epochs result

Is that a kind of local minima (or saddle point?) that predicts everything as background (the most frequent label)?

What is the reason, what are your ideas? And also is there any proper way for visualization of semantic segmentation?

I guess there is something wrong about training. If there is overfitting, losses have always decreased, why is the result the same for traning data.

acc

loss

2 Answers
Related