def minimize(fn, epochs, batch_shape): print('\n\nInfusing CONTENT with STYLE...\n') t0 = datetime.now() losses = [] epoch_duration = [] epoch_duration_float = [] x = np.random.randn(np.prod(batch_shape)) for i in range(epochs): x, l, _ = fmin_l_bfgs_b(func=fn, x0=x, maxfun=20) x = np.clip(x, -127, 127) dt = datetime.now() - t0 total_min = dt.total_seconds() / 60 epoch_duration.append(dt) epoch_duration_float.append(total_min) print("epoch=%s, loss=%s, epoch duration = %s, total min = %.3f" % (i, l, dt, total_min)) losses.append(l) dt = datetime.now() - t0 print("\nTotal duration: %.3f" % np.array(epoch_duration_float).sum() + ' min') plt.plot(losses) plt.title("Optimization losses\nElapsed time: %.3f" % np.array(epoch_duration_float).sum() + " min") plt.show() plt.plot(epoch_duration_float, color='orange') plt.title('Epoch duration (minutes)') plt.xlabel('Epoch') plt.ylabel('Minutes') plt.show() newimg = x.reshape(*batch_shape) final_img = unpreprocess(newimg) return final_img[0]
def minimize(fn, epochs, batch_shape): t0 = datetime.now() losses = [] x = np.random.randn(np.prod(batch_shape)) for i in range(epochs): x, l, _ = fmin_l_bfgs_b(func=fn, x0=x, maxfun=20) x = np.clip(x, -127, 127) print("iter=%s, loss=%s" % (i, l)) losses.append(l) print("duration:", datetime.now() - t0) plt.plot(losses) plt.show() newimg = x.reshape(*batch_shape) final_img = unpreprocess(newimg) return final_img[0]
def minimize(fn, epochs, batch_shape): t0 = datetime.now() losses = [] x = np.random.randn(np.prod(batch_shape)) for i in range(epochs): x, l, _ = fmin_l_bfgs_b( func=fn, x0=x, maxfun=20 ) x = np.clip(x, -127, 127) print("iter=%s, loss=%s" % (i, l)) losses.append(l) print("duration:", datetime.now() - t0) plt.plot(losses) plt.show() newimg = x.reshape(*batch_shape) final_img = unpreprocess(newimg) return final_img[0]