############################################### # Action 1) Get max activation for a slection of feat maps ############################################### get_max_act = False if get_max_act: if not model: model = load_model('./Data/vgg16_weights.h5') if not Dec: Dec = KerasDeconv.DeconvNet(model) d_act_path = './Data/dict_top9_mean_act.pickle' d_act = {"convolution2d_13": {}, "convolution2d_10": {} } for feat_map in range(10): d_act["convolution2d_13"][feat_map] = find_top9_mean_act( data, Dec, "convolution2d_13", feat_map, batch_size=32) d_act["convolution2d_10"][feat_map] = find_top9_mean_act( data, Dec, "convolution2d_10", feat_map, batch_size=32) with open(d_act_path, 'w') as f: pickle.dump(d_act, f) ############################################### # Action 2) Get deconv images of images that maximally activate # the feat maps selected in the step above ############################################### deconv_img = False if deconv_img: d_act_path = './Data/dict_top9_mean_act.pickle' d_deconv_path = './Data/dict_top9_deconv.pickle' if not model: model = load_model('./Data/vgg16_weights.h5')
deconv_model = deconv_models.Conv(pretrained=True) out = model.predict(data) #print(model.summary()) out = deconv_model.predict(out) raise ValueError if not Dec: Dec = KerasDeconv.DeconvNet(model) if get_max_act: layers = ['block1_conv1', 'block1_conv2', 'pool1', 'block2_conv1', 'pool2', 'block2_conv2', 'pool3'] layer = layers[4] d_act_path = './data/dict_top9_mean_act.pickle' d_act = {layer: {}, } ## Filters to check for feat_map in [3, 4]: d_act[layer][feat_map] = find_top9_mean_act( data, Dec, layer, feat_map, batch_size=32) with open(d_act_path, 'w') as f: pickle.dump(d_act, f) ############################################### # Action 2) Get deconv images of images that maximally activate # the feat maps selected in the step above ############################################### deconv_img = True if deconv_img: d_act_path = './data/dict_top9_mean_act.pickle' d_deconv_path = './data/dict_top9_deconv.pickle' #get_deconv_images(d_act_path, d_deconv_path, data, Dec) raise ValueError