MCPcopy
hub / github.com/junyanz/iGAN / def_bfgs

Function def_bfgs

iGAN_predict.py:33–59  ·  view source on GitHub ↗
(model_G, layer='conv4', npx=64, alpha=0.002)

Source from the content-addressed store, hash-verified

31
32
33def def_bfgs(model_G, layer='conv4', npx=64, alpha=0.002):
34 print('COMPILING...')
35 t = time()
36
37 x_f = T.tensor4()
38 x = T.tensor4()
39 z = T.matrix()
40 tanh = activations.Tanh()
41 gx = model_G(tanh(z))
42
43 if layer is 'hog':
44 gx_f = HOGNet.get_hog(gx, use_bin=True, BS=4)
45 else:
46 gx_t = AlexNet.transform_im(gx)
47 gx_net = AlexNet.build_model(gx_t, layer=layer, shape=(None, 3, npx, npx))
48 AlexNet.load_model(gx_net, layer=layer)
49 gx_f = lasagne.layers.get_output(gx_net[layer], deterministic=True)
50
51 f_rec = T.mean(T.sqr(x_f - gx_f), axis=(1, 2, 3)) * sharedX(alpha)
52 x_rec = T.mean(T.sqr(x - gx), axis=(1, 2, 3))
53 cost = T.sum(f_rec) + T.sum(x_rec)
54 grad = T.grad(cost, z)
55 output = [cost, grad, gx]
56 _invert = theano.function(inputs=[z, x, x_f], outputs=output)
57
58 print('%.2f seconds to compile _bfgs function' % (time() - t))
59 return _invert, z
60
61
62def def_predict(model_P):

Callers 1

def_invert_modelsFunction · 0.85

Calls 2

sharedXFunction · 0.90
get_hogMethod · 0.80

Tested by

no test coverage detected