コード例 #1
0
ファイル: hsv2.py プロジェクト: yaxinshen/test
    data = data.reshape((n * data.shape[1], n * data.shape[3]) +
                        data.shape[4:])

    plt.imshow(data)
    plt.axis('off')
    plt.show()


if __name__ == '__main__':
    caffe.set_device(0)
    caffe.set_mode_gpu()

    net_file = '/home/shenyaxin/color/deploy.prototxt'
    caffe_model = '/core1/data/home/liuhuawei/tools/models/bvlc_reference_caffenet.caffemodel'
    net = caffe.Net(net_file, caffe_model, caffe.TEST)
    mysql = MysqlOperator()
    #shop_mete = get_data(mysql, 0)
    datas = get_data(mysql, 1)
    src_id_list = []
    fea_list = []
    batch_size = 32
    bs = 32
    for i in range(0, len(datas), batch_size):
        if (i + batch_size) > len(datas):
            bs = len(datas) - i
        data_batch = datas[i:i + bs]
        imgs = []
        hsvs = []
        hists = []
        itemids = []
        for data in data_batch:
コード例 #2
0
def deconv_each():
    caffe.set_device(1)
    caffe.set_mode_gpu()

    net_file = '/home/shenyaxin/color/deploy.prototxt'
    denet_file = '/home/shenyaxin/color/each_filter.prototxt'
    caffe_model = '/core1/data/home/liuhuawei/tools/models/bvlc_reference_caffenet.caffemodel'
    net = caffe.Net(net_file, caffe_model, caffe.TEST)
    denet = caffe.Net(denet_file, caffe.TEST)
    mysql = MysqlOperator()
    #shop_mete = get_data(mysql, 0)
    datas = get_data(mysql, 1)
    src_id_list = []
    fea_list = []
    batch_size = 1
    bs = 1
    for i in range(0, len(datas), batch_size):
        if (i + batch_size) > len(datas):
            bs = len(datas) - i
        data_batch = datas[i:i + bs]
        imgs = []
        itemids = []
        for data in data_batch:
            itemid = data['src_id']
            itemids.append(itemid)
            path = data['url']
            xmin = int(data['xmin'])
            ymin = int(data['ymin'])
            width = int(data['width'])
            height = int(data['height'])
            bbox = [xmin, ymin, xmin + width, ymin + height]
            img = transform_img(path, bbox)
            imgs.append(img)

        #transformerd = caffe.io.Transformer({'test_photod': net.blobs['data'].data.shape})
        #transformerd.set_transpose('test_photod', (2, 0, 1))
        #transformerd.set_mean('test_photod', np.array([104,117,123]))
        imgs = np.array(imgs)
        net.blobs["data"].reshape(bs, 3, 224, 224)
        net.blobs["data"].data[...] = imgs
        output = net.forward()
        all_de = []  #print net.params['conv1'][0].shape
        for step in range(0, 96):
            denet.params['conv1'][0].data[
                ...] = net.params['conv1'][0].data[step].reshape(
                    denet.params['conv1'][0].data.shape)
            denet.params['conv1t'][0].data[
                ...] = net.params['conv1'][0].data[step].reshape(
                    denet.params['conv1t'][0].data.shape)
            denet.blobs["data"].reshape(bs, 3, 224, 224)
            denet.blobs["data"].data[...] = imgs
            deout = denet.forward()
            img_t = denet.blobs['conv1t'].data.copy()
            #print net.params['conv1'][0].data.shape, img_t.shape
            img_t = detrans(img_t)
            #print imgs.shape, img_t.shape
            #plt.subplot(1,2,1)
            #plt.title('origin')
            #plt.imshow(imgs[0].transpose((1,2,0)))
            #plt.axis('off')
            #plt.subplot(1,2,2)
            #plt.title('deconv')
            #plt.imshow(img_t[0].transpose((1,2,0)))
            #plt.axis('off')
            #plt.show()
            #plt.savefig('1.png')
            imga = imgs[0, (1, 2, 0), :, :].transpose((1, 2, 0)).astype(int)
            imgb = img_t[0, (1, 2, 0), :, :].transpose((1, 2, 0)).astype(int)
            all_de.append(imgb)
        all_de = np.array(all_de)
        vis_square(all_de, i)
        #misc.imsave('img/%d1.png'%(i),imga)
        #misc.imsave('img/%d2.png'%(i),imgb)
        #with open('1.txt','w') as f:
        #    f.write(str(imgs[0]))
        #with open('2.txt','w') as f2:
        #    f2.write(str(img_t[0]))
        if i == 10:
            exit()