Exemplo n.º 1
0
def test_activation_maximization(vgg):
    deo = Model(vgg)

    layer_list = [layer.name for layer in vgg.layers[1:4]]

    for i, layer in enumerate(layer_list):
        outs = deprocess_image(
            deo.activation_maximization(layer, epochs=5, step_size=2)[0])
Exemplo n.º 2
0
def test_max_filter(vgg):
    deo = Model(vgg)

    img = load_image('tests/img/cat.jpg')

    layer_list = [layer.name for layer in vgg.layers[1:4]]

    for i, layer in enumerate(layer_list):
        deo.max_filter(layer, img)
Exemplo n.º 3
0
def test_guided_backprop(vgg):
    # load the vgg into the deoxys model
    deo = Model(vgg)

    # load an real image
    img = load_image('tests/img/cat.jpg')

    layer_list = [layer.name for layer in vgg.layers[1:4]]

    for i, layer in enumerate(layer_list):
        outs = deprocess_image(deo.guided_backprop(layer, img, mode='mean')[0])
Exemplo n.º 4
0
def test_deconvnet(vgg):

    # load the vgg into the deoxys model
    deo = Model(vgg)

    # load an real image
    img = load_image('tests/img/cat.jpg')

    layer_list = [layer.name for layer in vgg.layers[1:4]]

    for i, layer in enumerate(layer_list):
        deprocess_image(deo.deconv(layer, img, mode='min')[0])
Exemplo n.º 5
0
def test_activation_map(vgg):
    # load the vgg into the deoxys model
    deo = Model(vgg)

    # load an real image
    img = load_image('tests/img/cat.jpg')

    # View activation map, 1st filters
    layer_list = [layer.name for layer in vgg.layers[1:4]]

    for i, layer in enumerate(layer_list):
        outs = deprocess_image(deo.activation_map(layer, img)[0][..., 0])
Exemplo n.º 6
0
def load_image(path, target_size=(224, 224)):
    x = image.load_img(path, target_size=target_size)
    x = image.img_to_array(x)
    x = np.expand_dims(x, axis=0)
    x = preprocess_input(x)

    return x


if __name__ == '__main__':
    vgg = vgg16.VGG16(weights='imagenet', include_top=True)
    vgg.summary()

    # load the vgg into the deoxys model
    deo = Model(vgg)

    # load an real image
    img = load_image('../../test_img/cat.jpg')

    # predict what is in that image
    preds = deo.predict(img)
    predicted_class = preds.argmax(axis=1)[0]

    print("predicted top1 class:", predicted_class)
    print('Predicted:', decode_predictions(preds, top=1)[0])

    # View activation map, 1st filters
    layer_list = [layer.name for layer in vgg.layers[1:19]]
    nrow, ncol = 4, 5