MCPcopy Index your code
hub / github.com/lazyprogrammer/machine_learning_examples / minimize

Function minimize

cnn_class2/style_transfer2.py:47–67  ·  view source on GitHub ↗
(fn, epochs, batch_shape)

Source from the content-addressed store, hash-verified

45
46# let's generalize this and put it into a function
47def minimize(fn, epochs, batch_shape):
48 t0 = datetime.now()
49 losses = []
50 x = np.random.randn(np.prod(batch_shape))
51 for i in range(epochs):
52 x, l, _ = fmin_l_bfgs_b(
53 func=fn,
54 x0=x,
55 maxfun=20
56 )
57 x = np.clip(x, -127, 127)
58 print("iter=%s, loss=%s" % (i, l))
59 losses.append(l)
60
61 print("duration:", datetime.now() - t0)
62 plt.plot(losses)
63 plt.show()
64
65 newimg = x.reshape(*batch_shape)
66 final_img = unpreprocess(newimg)
67 return final_img[0]
68
69
70if __name__ == '__main__':

Callers 2

style_transfer3.pyFile · 0.90
style_transfer2.pyFile · 0.85

Calls 1

unpreprocessFunction · 0.90

Tested by

no test coverage detected