Beispiel #1
0
                             pixel_std=[70.30930, 69.41244, 72.60676])
dataload = ImageSetLoader(**init_args['image_set_loader']['train'])

model = load_model(
    '/tmp/fcn_vgg16_weights.h5',
    custom_objects={
        'CroppingLike2D':
        CroppingLike2D,
        #'mean_categorical_crossentropy': mean_categorical_crossentropy})
        'flatten_categorical_crossentropy':
        flatten_categorical_crossentropy(classes=21)
    })
print(model.summary())

for fn in dataload.filenames[:10]:
    x = dataload.load_img(fn)
    x = datagen.standardize(x)
    print(x.min(), x.max())
    X = x[np.newaxis, ...]
    label = dataload.load_seg(fn)
    label = np.squeeze(label, axis=-1).astype('int')
    y_enc = np.eye(21)[label]
    y_true = y_enc[np.newaxis, ...]
    result = model.evaluate(X, y_true)

    y_pred = model.predict(X)
    print(np.unique(y_true), np.unique(y_pred))
    loss = mean_categorical_crossentropy(K.variable(y_true),
                                         K.variable(y_pred))
    print(y_true.shape, y_pred.shape)
    print(result, K.eval(loss))
Beispiel #2
0
datagen = PascalVocGenerator(image_shape=[224, 224, 3],
                             image_resample=True,
                             pixelwise_center=True,
                             pixel_mean=[115.85100, 110.50989, 102.16182],
                             pixelwise_std_normalization=True,
                             pixel_std=[70.30930, 69.41244, 72.60676])
dataload = ImageSetLoader(**init_args['image_set_loader']['train'])

model = load_model('/tmp/fcn_vgg16_weights.h5',
        custom_objects={'BilinearUpSampling2D': BilinearUpSampling2D})
print(model.summary())


for fn in dataload.filenames[:10]:
    x = dataload.load_img(fn)
    x = datagen.standardize(x)
    print(x.min(), x.max())
    X = x[np.newaxis, ...]
    label = dataload.load_seg(fn)
    label = np.squeeze(label, axis=-1).astype('int')
    y_enc = np.eye(21)[label]
    y_true = y_enc[np.newaxis, ...]
    result = model.evaluate(X, y_true)

    y_pred = model.predict(X)
    print(np.unique(y_true), np.unique(y_pred))
    loss = keras.losses.categorical_crossentropy(K.variable(y_true), K.variable(y_pred))
    print(y_true.shape, y_pred.shape)
    print(result, K.eval(loss))
Beispiel #3
0
datagen = PascalVocGenerator(image_shape=[224, 224, 3],
                             image_resample=True,
                             pixelwise_center=True,
                             pixel_mean=[115.85100, 110.50989, 102.16182],
                             pixelwise_std_normalization=True,
                             pixel_std=[70.30930, 69.41244, 72.60676])
dataload = ImageSetLoader(**init_args['image_set_loader']['test'])

model = load_model(
    '/usr/local/workspace/keras-fcn/voc2011/tmp/fcn_vgg16_weights.h5',
    custom_objects={'BilinearUpSampling2D': BilinearUpSampling2D})
print(model.summary())

for fn in dataload.filenames[:10]:
    x = dataload.load_img(fn)
    x = datagen.standardize(x)
    print(x.min(), x.max())
    X = x[np.newaxis, ...]
    label = dataload.load_seg(fn)
    label = np.squeeze(label, axis=-1).astype('int')
    y_enc = np.eye(21)[label]
    y_true = y_enc[np.newaxis, ...]
    result = model.evaluate(X, y_true)

    y_pred = model.predict(X)
    print(np.unique(y_true), np.unique(y_pred))
    loss = keras.losses.categorical_crossentropy(K.variable(y_true),
                                                 K.variable(y_pred))
    print(y_true.shape, y_pred.shape)
    print(result, K.eval(loss))