コード例 #1
0
def generate_layers(path, filename, out_path):
    for i, layer in enumerate(layers):
        print i
        sys.stdout.flush()
        ts = time.time()
        im = np.asarray(Image.open(os.path.join(path, filename)).convert('RGB').resize((256, 256), resample=Image.ANTIALIAS)) \
                        .transpose(2, 0, 1).reshape((1, 3, 256, 256))[:, :, 16:-16][:, :, :, 16:-16]
        im_name = filename[:filename.find('.')]
        dirname = os.path.join(out_path,im_name)
        if not os.path.exists(dirname):
            os.mkdir(dirname)
        if layer is not None:
            STATS = STAT_LIST[:layer]
        else:
            STATS = STAT_LIST

        stim_name = os.path.join(dirname, im_name+'_layer'+str(i)+'.npy')
        r, targets = thing4.main(pf, sf, stim_name,
                                 [(im, STATS)],
                                 use_bounds=True,
                                 data_layer='data',
                                 start_layer='conv1_1',
                                 start_normal=False,
                                 crop=(16, -16, 16, -16),
                                 save_dir = os.path.join(dirname, im_name+'_layer'+str(i)+'_history'),
                                 save_freq=100,
                                 seed=0)
        save_stim(stim_name)
        print time.time()-ts
        sys.stdout.flush()
コード例 #2
0
def generate_layers(path, filename, out_path):
    seed = np.random.randint(2**32)
    print 'Seed used:', seed
    for i, layer in enumerate(layers):
        print i
        sys.stdout.flush()
        ts = time.time()
        im = get_image(os.path.join(path, filename))
        im_name = filename[:filename.find('.')]
        dirname = os.path.join(out_path, im_name)
        if not os.path.exists(dirname):
            os.mkdir(dirname)
        orig = im.squeeze().transpose((1, 2, 0)).astype('uint8')
        img = Image.fromarray(orig, 'RGB')
        img.save(os.path.join(dirname, im_name + '.o.jpg'))
        if layer is not None:
            STATS = STAT_LIST[:layer]
        else:
            STATS = STAT_LIST

        stim_name = os.path.join(dirname, im_name + '_layer' + str(i) + '.npy')
        r, targets = thing4.main(pf,
                                 sf,
                                 stim_name, [(im, STATS)],
                                 use_bounds=True,
                                 data_layer='data',
                                 start_layer='conv1_1',
                                 start_normal=False,
                                 crop=(16, -16, 16, -16),
                                 save_dir=os.path.join(
                                     dirname,
                                     im_name + '_layer' + str(i) + '_history'),
                                 save_freq=100,
                                 seed=seed)
        save_stim(stim_name)
        print time.time() - ts
        sys.stdout.flush()
コード例 #3
0
             ('pool4', 100, 'corr_rs')]

pf = 'model.prototxt'
sf = 'model_parameters.caffemodel'

layers = [1, 3, 6, 11, None]
for i, layer in enumerate(layers):
    print i
    sys.stdout.flush()
    ts = time.time()
    im = 'campbell256.o.jpg'
    im2 = np.asarray(Image.open('textures/texture_jpgs/'+im).convert('RGB').resize((256, 256), resample=Image.ANTIALIAS)).transpose(2, 0, 1).reshape((1, 3, 256, 256))[:, :, 16:-16][:, :, :, 16:-16]
    im_name = im[:im.find('.')]+'_p2_layer'+str(i)
    dirname = 'textures/generated/'+im_name
    if layer is not None:
        STATS = STAT_LIST[:layer]
    else:
        STATS = STAT_LIST

    r, targets = thing4.main(pf, sf, os.path.join(dirname, 'genstim.npy'),
                             [(im2, STATS)],
                             use_bounds=True,
                             data_layer='data',
                             start_layer='conv1_1',
                             start_normal=False,
                             crop=(16, -16, 16, -16),
                             save_dir = os.path.join(dirname, 'history'),
                             save_freq=100,
                             seed=0)
    print time.time()-ts
    sys.stdout.flush()
コード例 #4
0
mean = np.load('/home/ubuntu/new/caffe/audio_batches_mean.npy')

x = cPickle.load(open('/home/ubuntu/new/caffe/cgrams.cpy'))
im = Image.fromarray((np.tile(x['all_cgrams'][:, :, -14],
                              (3, 1, 1)) * 255).astype(np.uint8).transpose(
                                  (1, 2, 0))).resize((225, 225))
im = np.asarray(im).transpose((2, 0, 1)).reshape((1, 3, 225, 225))
print(im.shape)
r, targets = thing4.main(
    pf,
    sf,
    '/home/ubuntu/test_audio_real2/test_real.npy',
    [(
        im,
        [  #('conv1', 1, 'corr_t'), 
            #('pool1', 1, 'corr_t'),
            #('conv2', 1, 'corr_t'),
            #('pool2', 1, 'corr_t'),
            #('conv3', 1, 'corr_t'),
            #('conv4', 1, 'corr_t'),
            #('conv5', 1, 'corr_t'),
            ('pool5', 1, 'corr_t')
        ])],
    'data',
    seed=0,
    use_bounds=True,
    mean=mean,
    save_dir='/home/ubuntu/test_audio_real2/things/',
    save_freq=100,
    start_normal='zeros')
コード例 #5
0
import numpy as np

import thing4
reload(thing4)
import dldata.stimulus_sets.hvm as hvm
from collections import OrderedDict

pf = '/home/ubuntu/new/caffe/examples/cifar10/caffenet_rand.prototxt'
sf = '/home/ubuntu/new/caffe/examples/cifar10/bvlc_reference_caffenet.caffemodel'

#im0 = 255*imgs[0].transpose((2, 0, 1)).reshape((1, 3, 256, 256))
#im1 = 255*imgs[-1].transpose((2, 0, 1)).reshape((1, 3, 256, 256))

var = np.array([-1] + [0] * 4095).astype(np.float32)

r = thing4.main(pf,
                sf,
                '/home/ubuntu/test_O3_bounds_s.npy',
                targets0=[(None, [('fc6', 1, ('max', var))])],
                crop=(14, -15, 14, -15),
                use_bounds=True,
                seed=1)
コード例 #6
0
import thing4
import dldata.stimulus_sets.hvm as hvm
from collections import OrderedDict

pf = '/home/ubuntu/new/caffe/examples/cifar10/cifar10_quick_train_test_rand.prototxt'
sf = '/home/ubuntu/new/caffe/examples/cifar10/cifar10_quick_iter_5000.caffemodel.h5'

import numpy as np

v = np.load('/home/ubuntu/new/caffe/data_target.npy')

im = v[2]

#r, targets = thing4.main(pf, sf, '/home/ubuntu/test_xc.npy',  [(im, [('conv1', 200, 'corr'), ('conv2', 200, 'corr'), ('c#onv3', 200, 'corr')])], 'data', mean=np.zeros_like(v[0]))

r, targets = thing4.main(pf,
                         sf,
                         '/home/ubuntu/test_yc1.npy',
                         [(im, [('pool3', 100, 'corr')])],
                         'data',
                         mean=np.zeros_like(v[0]))
コード例 #7
0
im = Image.fromarray((np.tile(x['all_cgrams'][:, :, 8],
                              (3, 1, 1)) * 255).astype(np.uint8).transpose(
                                  (1, 2, 0))).resize((225, 225),
                                                     resample=Image.ANTIALIAS)
im = np.asarray(im).transpose((2, 0, 1)).reshape((1, 3, 225, 225))
print(im.shape)
r, targets = thing4.main(
    pf,
    sf,
    '/home/ubuntu/test_audio_stim4a_diag/test_real.npy',
    [(
        im,
        [
            ('conv1', 1, 'corr_diag'),
            ('pool1', 1, 'corr_diag'),
            ('conv2', 1, 'corr_diag'),
            ('pool2', 1, 'corr_diag'),
            ('conv3', 1000, 'corr_diag'),
            ('conv4', 100000, 'corr_diag'),
            ('conv5', 100000, 'corr_diag'),
            ('pool5', 100000, 'corr_diag'),
            #('fc6', 100000, 'ss')
        ])],
    'data',
    seed=2,
    use_bounds=True,
    #start_normal=False, start_im = im,
    mean=mean,
    save_dir='/home/ubuntu/test_audio_stim4a_diag/things/',
    save_freq=100)
コード例 #8
0
r, targets = thing4.main(
    pf,
    sf,
    os.path.join(dirname, 'genstim.npy'),
    [(
        im2,
        [
            ('conv1', 100, 'corr'),
            ('norm1', 100, 'corr'),
            ('pool1', 100, 'corr'),
            (
                'conv2',
                10000,
                'corr',
            ),
            ('norm2', 100, 'corr'),
            ('pool2', 100, 'corr'),
            ('conv3', 10000, 'corr'),
            ('conv4', 100000, 'corr'),
            ('conv5', 1000000, 'corr'),
            ('pool5', 1000000, 'corr'),
            #('fc6', 10000, 'ss'),
            #('fc7', 10000, 'ss'),
            #('fc8', 10000, 'ss')
        ])],
    use_bounds=True,
    data_layer='data',
    start_normal=False,
    crop=(14, -15, 14, -15),
    save_dir=os.path.join(dirname, 'history'),
    save_freq=100,
    seed=0)
コード例 #9
0
im = np.asarray(
    Image.open('/home/ubuntu/imgres.jpg').resize(
        (256, 256), resample=Image.ANTIALIAS)).transpose(2, 0, 1).reshape(
            (1, 3, 256, 256))[:, :, 14:-15][:, :, :, 14:-15]

im1 = np.asarray(
    Image.open('/home/ubuntu/imgres-1.jpg').resize(
        (256, 256), resample=Image.ANTIALIAS)).transpose(2, 0, 1).reshape(
            (1, 3, 256, 256))[:, :, 14:-15][:, :, :, 14:-15]

var = np.zeros((1000, )).astype(np.float32)
#var = np.zeros((4096,)).astype(np.float32)
var[0] = 1

#r, targets = thing4.main(pf, sf, '/home/ubuntu/test_something4.npy',  [([im], [('pool1', 100, 'corr')]), (None, [('fc8', 1, ('max', var))])], 'data', use_bounds=True, crop=(14, -15, 14, -15))

r, targets = thing4.main(pf,
                         sf,
                         '/home/ubuntu/genstim10/genstim.npy',
                         [(None, [('data', .01, 'smooth'),
                                  ('fc8', (10000, var), 'softmax')]),
                          ([im], [('pool1', 20, 'corr')])],
                         data_layer='data',
                         use_bounds=True,
                         crop=(14, -15, 14, -15),
                         start_normal=True,
                         seed=1,
                         start_im=im,
                         save_dir='/home/ubuntu/genstim10/things',
                         save_freq=100)
コード例 #10
0
import thing4
import dldata.stimulus_sets.hvm as hvm
from collections import OrderedDict

preproc = OrderedDict([(u'normalize', False), (u'dtype', u'float32'),
                       (u'resize_to', [256, 256, 3]), (u'mode', u'RGB'),
                       (u'crop', None), (u'mask', None)])

dataset = hvm.HvMWithDiscfade()
imgs = dataset.get_images(preproc=preproc)
pf = '/home/ubuntu/new/caffe/examples/cifar10/caffenet_rand.prototxt'
sf = '/home/ubuntu/new/caffe/examples/cifar10/bvlc_reference_caffenet.caffemodel'

#im0 = 255*imgs[0].transpose((2, 0, 1)).reshape((1, 3, 256, 256))
#im1 = 255*imgs[-1].transpose((2, 0, 1)).reshape((1, 3, 256, 256))
meta = dataset.meta
inds = (meta['category'] == 'Cars').nonzero()[0]
ims = [
    255 * imgs[i][14:-15][:, 14:-15].transpose((2, 0, 1)).reshape(
        (1, 3, 227, 227)) for i in inds[::20][:10]
]

r, targets = thing4.main(pf,
                         sf,
                         '/home/ubuntu/test_fc6_cn_cars3.npy',
                         [(ims[0], [('conv1', .5, 'ss')]),
                          (ims[1], [('conv5', 10, 'corr')])],
                         'data',
                         crop=(14, -15, 14, -15))
コード例 #11
0
 im_name = im[:im.find('.')] + '_p2'
 dirname = 'textures/generated/' + im_name
 r, targets = thing4.main(pf,
                          sf,
                          os.path.join(dirname, 'genstim.npy'),
                          [(im2, [('conv1_1', 1000, 'corr_rs'),
                                  ('conv1_2', 100, 'corr_rs'),
                                  ('pool1', 100, 'corr_rs'),
                                  ('conv2_1', 100, 'corr_rs'),
                                  ('conv2_2', 100, 'corr_rs'),
                                  ('pool2', 100, 'corr_rs'),
                                  ('conv3_1', 100, 'corr_rs'),
                                  ('conv3_2', 100, 'corr_rs'),
                                  ('conv3_3', 100, 'corr_rs'),
                                  ('conv3_4', 100, 'corr_rs'),
                                  ('pool3', 10, 'corr_rs'),
                                  ('conv4_1', 100, 'corr_rs'),
                                  ('conv4_2', 100, 'corr_rs'),
                                  ('conv4_3', 100, 'corr_rs'),
                                  ('conv4_4', 1000, 'corr_rs'),
                                  ('pool4', 100, 'corr_rs')])],
                          use_bounds=True,
                          data_layer='data',
                          start_layer='conv1_1',
                          start_normal=False,
                          crop=(16, -16, 16, -16),
                          save_dir=os.path.join(dirname, 'history'),
                          save_freq=100,
                          seed=0)
 print time.time() - ts
 sys.stdout.flush()
コード例 #12
0
meta = dataset.meta
inds = (meta['category'] == 'Cars').nonzero()[0]
ims = [
    255 * imgs[i][14:-15][:, 14:-15].transpose((2, 0, 1)).reshape(
        (1, 3, 227, 227)) for i in inds
]
import numpy as np
from PIL import Image
im = np.asarray(
    Image.open('/home/ubuntu/imgres.jpg').resize(
        (256, 256), resample=Image.ANTIALIAS)).transpose(2, 0, 1).reshape(
            (1, 3, 256, 256))[:, :, 14:-15][:, :, :, 14:-15]

var = np.zeros((1000, )).astype(np.float32)
var[55] = -1

r, targets = thing4.main(pf,
                         sf,
                         '/home/ubuntu/genstim2.npy',
                         [(None, [('data', .1, 'smooth'),
                                  ('fc8', (100, var), 'max2')])],
                         'data',
                         use_bounds=True,
                         crop=(14, -15, 14, -15),
                         start_normal=True,
                         seed=2)

#r, targets = thing4.main(pf, sf, '/home/ubuntu/genstim2.npy',  [(None, [('fc8', (100, var), 'max')])], 'data', use_bounds=True, crop=(14, -15, 14, -15), start_normal=True, seed=2)

#r, targets = thing4.main(pf, sf, '/home/ubuntu/genstim2.npy',  [(None, [('data', 1, 'smooth')])], 'data', use_bounds=False, crop=(14, -15, 14, -15), start_normal=True, seed=0)
コード例 #13
0
im1 = np.asarray(
    Image.open('/home/ubuntu/test.png').convert('RGB').resize(
        (256, 256), resample=Image.ANTIALIAS)).transpose(2, 0, 1).reshape(
            (1, 3, 256, 256))[:, :, 14:-15][:, :, :, 14:-15]

im2 = np.asarray(
    Image.open('/home/ubuntu/imgres-2.png').convert('RGB').resize(
        (256, 256), resample=Image.ANTIALIAS)).transpose(2, 0, 1).reshape(
            (1, 3, 256, 256))[:, :, 14:-15][:, :, :, 14:-15]

#r, targets = thing4.main(pf, sf, '/home/ubuntu/test_y4a.npy',  [([ims[i] for i in range(640)], [('fc7', 100, 'ss'), ('fc6', 100, 'ss'), ('fc8', 100, 'ss')])], 'data', crop=(14, -15, 14, -15))

#r, targets = thing4.main(pf, sf, '/home/ubuntu/test_rocks_cn_pool.npy',  [(im1, [('conv1', 100, 'corr'), ('pool1', 100, 'corr'), ('conv2', 100, 'corr', ), ('pool2', 100, 'corr'),  ('conv3', 100, 'corr'), ('conv4', 100, 'corr'), ('conv5', 100, 'corr'), ('pool5', 100, 'corr')])], 'data', crop=(14, -15, 14, -15))

r, targets = thing4.main(pf,
                         sf,
                         '/home/ubuntu/test_fruits_cn_all.npy',
                         [(im2, [('conv1', 1000, 'corr'),
                                 ('pool1', 1000, 'corr'),
                                 ('conv2', 1000, 'corr'),
                                 ('pool2', 1000, 'corr'),
                                 ('conv5', 1000, 'corr'),
                                 ('pool5', 1000, 'corr'), ('fc6', 1000, 'ss'),
                                 ('fc7', 1000, 'ss')])],
                         use_bounds=True,
                         data_layer='data',
                         crop=(14, -15, 14, -15))

#r, targets = thing4.main(pf, sf, '/home/ubuntu/test_y3d.npy',  [(ims[0], [('conv1', 100, 'corr'), ('conv2', 100, 'corr', ), ('conv3', 100, 'corr'), ('conv4', 100, 'corr'), ('conv5', 100, 'corr')])], 'data', crop=(14, -15, 14, -15), use_bounds=True, start_normal=False)
コード例 #14
0
inds = (meta['category'] == 'Cars').nonzero()[0]
ims = [255*imgs[i][14:-15][:, 14:-15].transpose((2, 0, 1)).reshape((1, 3, 227, 227)) for i in inds]
import numpy as np
from PIL import Image
im = np.asarray(Image.open('/home/ubuntu/imgres.jpg').resize((256, 256), resample=Image.ANTIALIAS)).transpose(2, 0, 1).reshape((1, 3, 256, 256))[:, :, 14:-15][:, :, :, 14:-15]

#r, targets = thing4.main(pf, sf, '/home/ubuntu/test_y4a.npy',  [([ims[i] for i in range(640)], [('fc7', 100, 'ss'), ('fc6', 100, 'ss'), ('fc8', 100, 'ss')])], 'data', crop=(14, -15, 14, -15))

#r, targets = thing4.main(pf, sf, '/home/ubuntu/test_y3b.npy',  [(ims[-1], [('conv1', 100, 'corr'), ('conv2', 100, 'corr', ), ('conv5', 100, 'corr'), ('pool5', 100, 'ss')])], 'data', crop=(14, -15, 14, -15))

#r, targets = thing4.main(pf, sf, '/home/ubuntu/test_X.npy',  [([ims[i] for i in range(1)], [('conv5', 100, 'corr'), ('pool5', 100, 'ss'), ('fc7', 100, 'ss'), ('fc6', 100, 'ss'), ('fc8', 100, 'ss')])], 'data', crop=(14, -15, 14, -15))

#r, targets = thing4.main(pf, sf, '/home/ubuntu/test_X.npy',  [([ims[i] for i in range(640)], [('fc8', 10000, 'ss')])], 'data', crop=(14, -15, 14, -15), use_bounds=True)

#inds = (meta['category'] == 'Faces').nonzero()[0]
#ims = [255*imgs[i][14:-15][:, 14:-15].transpose((2, 0, 1)).reshape((1, 3, 227, 227)) for i in inds]
im = np.asarray(Image.open('/home/ubuntu/imgres.jpg').resize((256, 256), resample=Image.ANTIALIAS)).transpose(2, 0, 1).reshape((1, 3, 256, 256))[:, :, 14:-15][:, :, :, 14:-15]

im1 = np.asarray(Image.open('/home/ubuntu/imgres-1.jpg').resize((256, 256), resample=Image.ANTIALIAS)).transpose(2, 0, 1).reshape((1, 3, 256, 256))[:, :, 14:-15][:, :,:, 14:-15]

var = np.zeros((1000,)).astype(np.float32)
var[23] = -1

#r, targets = thing4.main(pf, sf, '/home/ubuntu/test_something4.npy',  [([im], [('pool1', 100, 'corr')]), (None, [('fc8', 1, ('max', var))])], 'data', use_bounds=True, crop=(14, -15, 14, -15))

r, targets = thing4.main(pf, sf, '/home/ubuntu/genstim7/genstim.npy', 
                   [(None, [('data', .001, 'smooth')]), 
                    ([im], [('fc8', 1, 'ss')])],
                     data_layer = 'data', use_bounds=True, crop=(14, -15, 14, -15), start_normal=True, seed=0, 
                     save_dir='/home/ubuntu/genstim7/things', save_freq=100)
コード例 #15
0
var = .001 * np.ones((1000, )).astype(np.float32)
#var = np.zeros((4096,)).astype(np.float32)
var[801] = -1

var2 = np.zeros((1000, )).astype(np.float32)
#var = np.zeros((4096,)).astype(np.float32)
var2[2] = 1

#r, targets = thing4.main(pf, sf, '/home/ubuntu/test_something4.npy',  [([im], [('pool1', 100, 'corr')]), (None, [('fc8', 1, ('max', var))])], 'data', use_bounds=True, crop=(14, -15, 14, -15))

dirname = '/home/ubuntu/genstim11d'
r, targets = thing4.main(
    pf,
    sf,
    os.path.join(dirname, 'genstim.npy'),
    [(
        None,
        [('data', 0.5, 'smoothsep2'), ('data', .01, 'smoothsep'),
         ('fc8', (25000, var), 'max')
         #('fc8', (25000, var2), 'logsoftmax')
         ])],
    data_layer='data',
    use_bounds=True,
    crop=(14, -15, 14, -15),
    start_normal=False,
    seed=2,
    #start_im = im,
    save_dir=os.path.join(dirname, 'things'),
    save_freq=100)
コード例 #16
0
pf = '/home/ubuntu/new/caffe/examples/cifar10/caffenet_rand.prototxt'
sf = '/home/ubuntu/new/caffe/examples/cifar10/bvlc_reference_caffenet.caffemodel'

#im0 = 255*imgs[0].transpose((2, 0, 1)).reshape((1, 3, 256, 256))
#im1 = 255*imgs[-1].transpose((2, 0, 1)).reshape((1, 3, 256, 256))
meta = dataset.meta
inds = (meta['category'] == 'Cars').nonzero()[0]
ims = [
    255 * imgs[i][14:-15][:, 14:-15].transpose((2, 0, 1)).reshape(
        (1, 3, 227, 227)) for i in inds
]
import numpy as np
from PIL import Image
im = np.asarray(
    Image.open('/home/ubuntu/imgres.jpg').resize(
        (256, 256), resample=Image.ANTIALIAS)).transpose(2, 0, 1).reshape(
            (1, 3, 256, 256))[:, :, 14:-15][:, :, :, 14:-15]

var = np.zeros((1000, )).astype(np.float32)
var[23] = -1

r, targets = thing4.main(pf,
                         sf,
                         '/home/ubuntu/genstim1.npy',
                         [(None, [('fc8', (100, var), 'max')])],
                         'data',
                         use_bounds=False,
                         crop=(14, -15, 14, -15),
                         start_normal=False,
                         start_im=im)
コード例 #17
0
import thing4
import dldata.stimulus_sets.hvm as hvm
from collections import OrderedDict


preproc = OrderedDict([(u'normalize', False), (u'dtype', u'float32'), (u'resize_to', [256, 256, 3]), (u'mode', u'RGB'), (u'crop', None), (u'mask', None)])

pf = '/home/ubuntu/new/caffe/examples/cifar10/audio2.prototxt'
sf = '/home/ubuntu/new/caffe/examples/cifar10/audio.caffemodel.h5'
import numpy as np
from PIL import Image
im = np.asarray(Image.open('/home/ubuntu/imgres.jpg').resize((256, 256), resample=Image.ANTIALIAS)).transpose(2, 0, 1).reshape((1, 3, 256, 256)) 

im1 = np.asarray(Image.open('/home/ubuntu/imgres-2.png').convert('RGB').resize((225, 225), resample=Image.ANTIALIAS)).transpose(2, 0, 1).reshape((1, 3, 225, 225)) 

mean = np.load('/home/ubuntu/new/caffe/audio_batches_mean.npy')

r, targets = thing4.main(pf, sf, '/home/ubuntu/test_audio_corr/test_bork.npy', [(im1, [('conv1', 1, 'corr_rs'), ('pool1', 1, 'corr_rs'), ('conv2', 1, 'corr_rs'), ('pool2', 1, 'corr_rs'), ('conv3', 1, 'corr_rs'), ('conv4', 1, 'corr_rs'),  ('conv5', 1, 'corr_rs'), ('pool5', 1, 'corr_rs')])], 'data', seed=2, use_bounds=True, mean=mean, save_dir = '/home/ubuntu/test_audio_corr/things/', save_freq=100)

コード例 #18
0
import thing4
import dldata.stimulus_sets.hvm as hvm
from collections import OrderedDict

preproc = OrderedDict([(u'normalize', False), (u'dtype', u'float32'),
                       (u'resize_to', [256, 256, 3]), (u'mode', u'RGB'),
                       (u'crop', None), (u'mask', None)])

dataset = hvm.HvMWithDiscfade()
imgs = dataset.get_images(preproc=preproc)
pf = '/home/ubuntu/new/caffe/examples/cifar10/roschinet_larger_rand_test.prototxt'
sf = '/home/ubuntu/new/caffe/examples/cifar10/roschinet_larger.caffemodel.h5'

im0 = imgs[0].transpose((2, 0, 1)).reshape((1, 3, 256, 256))
im1 = imgs[-1].transpose((2, 0, 1)).reshape((1, 3, 256, 256))
meta = dataset.meta
inds = meta['category'] == 'Cars'
ims = [
    imgs[i].transpose((2, 0, 1)).reshape((1, 3, 256, 256))
    for i in inds[::20][:10]
]
r, targets = thing4.main(pf, sf, '/home/ubuntu/test_ig.npy',
                         [(ims[i], [('conv4', 100, 'ss')]) for i in range(10)],
                         'data')
コード例 #19
0
            (1, 3, 256, 256))[:, :, 14:-15][:, :, :, 14:-15]

var = .001 * np.ones((1000, )).astype(np.float32)
#var = np.zeros((4096,)).astype(np.float32)
var[350] = -1

var2 = np.zeros((1000, )).astype(np.float32)
#var = np.zeros((4096,)).astype(np.float32)
var2[2] = 1

#r, targets = thing4.main(pf, sf, '/home/ubuntu/test_something4.npy',  [([im], [('pool1', 100, 'corr')]), (None, [('fc8', 1, ('max', var))])], 'data', use_bounds=True, crop=(14, -15, 14, -15))

r, targets = thing4.main(
    pf,
    sf,
    '/home/ubuntu/genstim15/genstim.npy',
    [(
        None,
        [('data', 0.5, 'smoothsep2'), ('data', .001, 'smoothsep'),
         ('fc8', (25000, var), 'max')
         #('fc8', (25000, var2), 'logsoftmax')
         ])],
    data_layer='data',
    use_bounds=True,
    crop=(14, -15, 14, -15),
    start_normal=False,
    seed=10,
    #start_im = im,
    save_dir='/home/ubuntu/genstim15/things',
    save_freq=100)
コード例 #20
0
def get_stim(fname, stat_n, stat_n2, seed, out_fname, save_freq, maxfun):
    impath = os.path.join(
        '/Users/babylab/Desktop/sandbox/textures/texture_jpgs/', fname)
    im_arr = np.asarray(
        Image.open(impath).convert('RGB').resize(
            (224, 224), resample=Image.ANTIALIAS)).transpose(2, 0, 1).reshape(
                (1, 3, 224, 224))

    if stat_n is not None:
        stat_list = STAT_LIST[:stat_n]
    else:
        stat_list = STAT_LIST[:]

    if stat_n2 is not None:
        stat_list += STAT_LIST_2[:stat_n2]

    dirname = os.path.join('/Users/babylab/Desktop/sandbox/textures/generated',
                           out_fname)
    final_path = os.path.join(dirname, 'genstim.npy')
    if os.path.exists(final_path):
        print('%s already finished, exiting' % dirname)
        return
    else:
        hdir = os.path.join(dirname, 'history')
        if os.path.isdir(hdir):
            hist = filter(lambda x: x.startswith('im_'), os.listdir(hdir))
        else:
            hist = []
        if len(hist) > 0:
            histints = [int(x.split('_')[-1].split('.')[0]) for x in hist]
            mhist = max(histints)
            start_path = os.path.join(hdir, 'im_%d.npy' % mhist)
            print('Starting with %s' % start_path)
            x0 = np.load(start_path)
            r, targets = thing4.main(pf,
                                     sf,
                                     final_path, [(im_arr, stat_list)],
                                     use_bounds=True,
                                     data_layer='data',
                                     start_layer='conv1_1',
                                     start_normal=False,
                                     start_im=x0,
                                     count_start=mhist,
                                     crop=(16, -16, 16, -16),
                                     save_dir=hdir,
                                     save_freq=save_freq,
                                     seed=seed,
                                     opt_kwargs={'maxfun': maxfun})

        else:
            print('Starting %s from scratch' % dirname)
            r, targets = thing4.main(pf,
                                     sf,
                                     final_path, [(im_arr, stat_list)],
                                     use_bounds=True,
                                     data_layer='data',
                                     start_layer='conv1_1',
                                     start_normal=False,
                                     crop=(16, -16, 16, -16),
                                     save_dir=hdir,
                                     save_freq=save_freq,
                                     seed=seed,
                                     opt_kwargs={'maxfun': maxfun})
        return r, targets
コード例 #21
0
x = cPickle.load(open('/home/ubuntu/new/caffe/cgrams.cpy'))
im = Image.fromarray((np.tile(x['all_cgrams'][:, :, -14],
                              (3, 1, 1)) * 255).astype(np.uint8).transpose(
                                  (1, 2, 0))).resize((225, 225),
                                                     resample=Image.ANTIALIAS)
im = np.asarray(im).transpose((2, 0, 1)).reshape((1, 3, 225, 225))
print(im.shape)
r, targets = thing4.main(
    pf,
    sf,
    '/home/ubuntu/test_audio_real_stim1a_max/test_real.npy',
    [(
        im,
        [  #('conv1', .1, 'corr_rs'), 
            #('pool1', .1, 'corr_rs'),
            #('conv2', 1, 'corr_rs'),
            ('pool2', 1, 'ss'),
            ('conv3', 1, 'ss'),
            ('conv4', 1, 'ss'),
            ('conv5', 1, 'ss'),
            ('pool5', 1, 'ss'),
            ('fc6', 1, 'ss')
        ])],
    'data',
    seed=0,
    use_bounds=True,
    mean=mean,
    save_dir='/home/ubuntu/test_audio_real_stim1a_max/things/',
    save_freq=100)
コード例 #22
0
from collections import OrderedDict

preproc = OrderedDict([(u'normalize', False), (u'dtype', u'float32'),
                       (u'resize_to', [256, 256, 3]), (u'mode', u'RGB'),
                       (u'crop', None), (u'mask', None)])

pf = '/home/ubuntu/new/caffe/examples/cifar10/audio2.prototxt'
sf = '/home/ubuntu/new/caffe/examples/cifar10/audio.caffemodel.h5'
import numpy as np
from PIL import Image
im = np.asarray(
    Image.open('/home/ubuntu/imgres.jpg').resize(
        (256, 256), resample=Image.ANTIALIAS)).transpose(2, 0, 1).reshape(
            (1, 3, 256, 256))

im1 = np.asarray(
    Image.open('/home/ubuntu/imgres-2.png').convert('RGB').resize(
        (225, 225), resample=Image.ANTIALIAS)).transpose(2, 0, 1).reshape(
            (1, 3, 225, 225))

mean = np.load('/home/ubuntu/new/caffe/audio_batches_mean.npy')

r, targets = thing4.main(pf,
                         sf,
                         '/home/ubuntu/test_audio2.npy',
                         [(im1, [('pool1', 1, 'ss')])],
                         'data',
                         seed=2,
                         use_bounds=True,
                         mean=mean)
コード例 #23
0
import thing4
import dldata.stimulus_sets.hvm as hvm
from collections import OrderedDict


preproc = OrderedDict([(u'normalize', False), (u'dtype', u'float32'), (u'resize_to', [256, 256, 3]), (u'mode', u'RGB'), (u'crop', None), (u'mask', None)])

dataset = hvm.HvMWithDiscfade()
imgs = dataset.get_images(preproc=preproc)
pf = '/home/ubuntu/new/caffe/examples/cifar10/roschinet_larger_rand_test.prototxt'
sf = '/home/ubuntu/new/caffe/examples/cifar10/roschinet_larger.caffemodel.h5'

im0 = 255*imgs[0].transpose((2, 0, 1)).reshape((1, 3, 256, 256))
im1 = 255*imgs[-1].transpose((2, 0, 1)).reshape((1, 3, 256, 256))
ims = [255*imgs[i].transpose((2, 0, 1)).reshape((1, 3, 256, 256)) for i in range(10)]
r, targets = thing4.main(pf, sf, '/home/ubuntu/test_x2_1.npy', [(ims[i], [('conv3', 10, 'ss')]) for i in range(10)] + \
                                                             [(ims[i], [('pool3', 10, 'ss')]) for i in range(10)], 'data')
コード例 #24
0
import thing4
import dldata.stimulus_sets.hvm as hvm
from collections import OrderedDict

preproc = OrderedDict([(u'normalize', False), (u'dtype', u'float32'),
                       (u'resize_to', [256, 256, 3]), (u'mode', u'RGB'),
                       (u'crop', None), (u'mask', None)])

dataset = hvm.HvMWithDiscfade()
imgs = dataset.get_images(preproc=preproc)
pf = '/home/ubuntu/new/caffe/examples/cifar10/roschinet_larger_rand_test.prototxt'
sf = '/home/ubuntu/new/caffe/examples/cifar10/roschinet_larger.caffemodel.h5'

im0 = imgs[0].transpose((2, 0, 1)).reshape((1, 3, 256, 256))
im1 = imgs[-1].transpose((2, 0, 1)).reshape((1, 3, 256, 256))
meta = dataset.meta
inds = (meta['category'] == 'Cars').nonzero()[0]
ims = [
    imgs[i].transpose((2, 0, 1)).reshape((1, 3, 256, 256))
    for i in inds[::20][:10]
]
r, targets = thing4.main(pf, sf, '/home/ubuntu/test_ih1.npy',
                         [([ims[i] for i in range(10)], [('fc6', 100, 'ss')])],
                         'data')
コード例 #25
0
#r, targets = thing4.main(pf, sf, '/home/ubuntu/test_something4.npy',  [([im], [('pool1', 100, 'corr')]), (None, [('fc8', 1, ('max', var))])], 'data', use_bounds=True, crop=(14, -15, 14, -15))

dirname = '/home/ubuntu/genstim14a'
r, targets = thing4.main(
    pf,
    sf,
    os.path.join(dirname, 'genstim.npy'),
    #[(None, [('data', .5, 'smoothsep2'),
    #        ('data', .005, 'smoothsep')])] + \
    [([im1], [
        ('fc8', 10000000, 'ss'),
        ('fc7', 100000, 'ss'),
        ('fc6', 1000000, 'ss'),
        ('pool5', 1000, 'corr_diag'),
        ('conv5', 100, 'corr_diag'),
        ('conv4', 100, 'corr_diag'),
        ('conv3', 100, 'corr_diag'),
        ('pool2', 100, 'corr_diag'),
        ('pool1', 100, 'corr_diag'),
        ('conv2', 100, 'corr_diag'),
        ('conv1', 100, 'corr_diag'),
    ]) for i in range(1)],
    data_layer='data',
    use_bounds=True,
    crop=(14, -15, 14, -15),
    start_normal=False,
    seed=1,
    #start_im = im,
    save_dir=os.path.join(dirname, 'things'),
    save_freq=100)
コード例 #26
0
ims = [
    255 * imgs[i][14:-15][:, 14:-15].transpose((2, 0, 1)).reshape(
        (1, 3, 227, 227)) for i in inds
]
import numpy as np
from PIL import Image
im = np.asarray(
    Image.open('/home/ubuntu/imgres.jpg').resize(
        (256, 256), resample=Image.ANTIALIAS)).transpose(2, 0, 1).reshape(
            (1, 3, 256, 256))[:, :, 14:-15][:, :, :, 14:-15]

#r, targets = thing4.main(pf, sf, '/home/ubuntu/test_y4a.npy',  [([ims[i] for i in range(640)], [('fc7', 100, 'ss'), ('fc6', 100, 'ss'), ('fc8', 100, 'ss')])], 'data', crop=(14, -15, 14, -15))

#r, targets = thing4.main(pf, sf, '/home/ubuntu/test_y3c.npy',  [(im, [('conv1', 100, 'corr'), ('conv2', 100, 'corr', ), ('conv3', 100, 'corr'), ('conv4', 100, 'corr'), ('conv5', 100, 'corr')])], 'data', crop=(14, -15, 14, -15), use_bounds=True start_normal=False)

r, targets = thing4.main(pf,
                         sf,
                         '/home/ubuntu/test_y3d.npy',
                         [(ims[0], [('conv1', 100, 'corr'),
                                    (
                                        'conv2',
                                        100,
                                        'corr',
                                    ), ('conv3', 100, 'corr'),
                                    ('conv4', 100, 'corr'),
                                    ('conv5', 100, 'corr')])],
                         'data',
                         crop=(14, -15, 14, -15),
                         use_bounds=True,
                         start_normal=False)