Example #1
0
def get_conv1_filter(param):
    param_images = []
    for i in range(param.shape[0]):
        img = param[i,:,:,:]
        img = np.transpose(img,(1,2,0))
        img = img - img.min()
        img = img / img.max()
        img = img*255
        img = img.astype(np.uint8)
        param_images.append(img)
        #print img

    show_filters = show_tile(param_images,100,1)[:,:,::-1]
    return show_filters
Example #2
0
save_iter = 200
while True:
    print "train stage 01 iter: %d to %d" % (train_iter01 * iter01,
                                             (train_iter01 + 1) * iter01)
    net = train_stage01.Train(np.int((train_iter01 + 1) * iter01), net)
    train_iter01 = train_iter01 + 1
    #train_stage02.ShareTrainedLayersWith(net)
    #train_stage02.net.share_with(train_stage01.net)
    print "train stage 02 iter: %d to %d" % (train_iter02 * iter02,
                                             (train_iter02 + 1) * iter02)
    net = train_stage02.Train(np.int((train_iter02 + 1) * iter02), net)
    train_iter02 = train_iter02 + 1
    #train_stage01.ShareTrainedLayersWith(net)
    #train_stage02.net.share_with(train_stage01.net)

    if count % save_iter == 0:
        net.forward()
        imgs = net.blobs['conv8_g'].data
        imgs = np.transpose(imgs, [0, 2, 3, 1])
        all_imgs = []
        for i in range(imgs.shape[0]):
            img_tmp = hard_tanh(imgs[i])
            all_imgs.append(img_tmp)
        show_imgs = show_tile(all_imgs, 144, 4)[:, :, ::-1]
        plt.imshow(show_imgs)
        plt.draw()
        #plt.show(block=False)
        plt.pause(0.001)
        plt.imsave('fig/exp2_epoch_%d.png' % (count / save_iter), show_imgs)
    count = count + 1
Example #3
0
            all_imgs.append(img_tmp)
        imgs = net.blobs['data'].data.copy()
        imgs = np.transpose(imgs, [0, 2, 3, 1])
        for i in range(4):  #imgs.shape[0]):
            img_tmp = hard_tanh(imgs[i])
            all_imgs.append(img_tmp)
    #train_stage02.ShareTrainedLayersWith(net)
    #train_stage02.net.share_with(train_stage01.net)
    print "train stage 02 iter: %d to %d" % (train_iter02 * iter02,
                                             (train_iter02 + 1) * iter02)
    net = train_stage02.Train(np.int((train_iter02 + 1) * iter02), net)
    train_iter02 = train_iter02 + 1
    #train_stage01.ShareTrainedLayersWith(net)
    #train_stage02.net.share_with(train_stage01.net)

    if count % save_iter == 0:
        net.forward()
        imgs = net.blobs['re_conv'].data.copy()
        imgs = np.transpose(imgs, [0, 2, 3, 1])
        #all_imgs = []
        for i in range(4):  #imgs.shape[0]):
            img_tmp = hard_tanh(imgs[i])
            all_imgs.append(img_tmp)
        show_imgs = show_tile(all_imgs, 144, 4)
        plt.imshow(show_imgs)
        plt.draw()
        #plt.show(block=False)
        plt.pause(0.001)
        #plt.imsave('fig/exp2_epoch_%d.png'%(count / save_iter),show_imgs)
    count = count + 1
Example #4
0
                input_diff = net.blobs['data'].diff.copy()
                #input_diff = np.sqrt((input_diff[0]**2).sum(axis=0))

                input_diff = np.transpose(input_diff[0], [1, 2, 0])
                input_diff = input_diff - input_diff.min()
                input_diff = input_diff / input_diff.max()
                input_diff = input_diff**2
                input_diff = input_diff / input_diff.max()

                input_diff = (input_diff[h_st:h_end, w_st:w_end, :] *
                              255).astype(np.uint8)

                if not input_diff.shape[0] * input_diff.shape[1] == 0:
                    top9_diff.append(input_diff)
                else:
                    top9_diff.append(np.zeros((100, 100, 3)))

        tmp_img = show_tile(top9_patch, 100, 1)[:, :, ::-1]
        all_top9_patch.append(tmp_img)
        if is_vis_diff:
            tmp_diff = show_tile((top9_diff), 100, 1)[:, :, ::-1]
            all_top9_diff.append(tmp_diff)

    tmp_img = show_tile(all_top9_patch, all_top9_patch[0].shape[0], 5)
    plt.imsave(save_name, tmp_img)
    if is_vis_diff:
        diff_img = show_tile(all_top9_diff, all_top9_diff[0].shape[0], 5)
        plt.imsave(save_name.replace(".png", "_diff.png"), diff_img)
    with open(save_name.replace(".png", "_top9.pickle"), 'wb') as fid:
        pickle.dump(top9_info, fid)
Example #5
0
                    #input_diff = np.sqrt((input_diff[0]**2).sum(axis=0))

                    input_diff = np.transpose(input_diff[0],[1,2,0])
                    input_diff = input_diff - input_diff.min()
                    input_diff = input_diff / input_diff.max()
                    input_diff = input_diff ** 2
                    input_diff = input_diff / input_diff.max()

                    input_diff = (input_diff[h_st:h_end,w_st:w_end,:]*255).astype(np.uint8)

                    if not input_diff.shape[0]*input_diff.shape[1]==0:
                        top9_diff.append(input_diff)
                    else:
                        top9_diff.append(np.zeros((100,100,3)))

            tmp_img = show_tile(top9_patch,100,1)[:,:,::-1]
            all_top9_patch.append(tmp_img)
            if is_vis_diff:
                tmp_diff = show_tile((top9_diff),100,1)[:,:,::-1]
                all_top9_diff.append(tmp_diff)
        total_top9_patch.append(all_top9_patch)
        if is_vis_diff:
            total_top9_diff.append(all_top9_diff)

        #tmp_img = show_tile(all_top9_patch,all_top9_patch[0].shape[0],5)
        #plt.imsave(save_name.replace(".png","_sub%02d.png"%(mask_idx)),tmp_img)
        #if is_vis_diff:
            #diff_img = show_tile(all_top9_diff,all_top9_diff[0].shape[0],5)
            #plt.imsave(save_name.replace(".png","_sub%02d_diff.png"%(mask_idx)),diff_img)
    all_vis_img =  []
    all_vis_diff = []