This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<reg51.h> | |
#define cmdport P3 | |
#define dataport P2 | |
#define q 10 | |
#define o 1 | |
sbit s1 = (P0^1); | |
sbit s2 = (P0^2); | |
sbit s3 = (P0^3); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
evaluator = Evaluator() | |
x = preprocess_img(base_path) | |
z = load_img(base_path,target_size=(img_nrows,img_ncols)) | |
imsave('iteration_original.png',z) | |
print "Saving original image.." | |
for i in range(EPOCHS): | |
print "Start iteration: %d" % i | |
start_time = time.time() | |
x,min_val,info = fmin_l_bfgs_b(evaluator.loss,x.flatten(),fprime=evaluator.grads,maxfun=20) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def eval_loss_and_grads(x): | |
x = x.reshape((1,3,img_nrows,img_ncols)) | |
outs = f_outputs([x]) | |
loss_value = outs[0] | |
if(len(outs[1:])==1): | |
grad_values = outs[1].flatten().astype('float64') | |
else: | |
grad_values = np.array(outs[1:]).flatten().astype('float64') | |
return loss_value,grad_values |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loss = K.variable(0.0) | |
layer_features = output_dict['block4_conv2'] | |
b_img_features = layer_features[0,:,:,:] | |
final_features = layer_features[2,:,:,:] | |
loss += content_wt * content_loss(b_img_features,final_features) | |
feature_layers = ['block1_conv1','block2_conv1','block3_conv1','block4_conv1','block5_conv1'] | |
for layer in feature_layers: | |
layer_features = output_dict[layer] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def content_loss(base,final): | |
return K.sum(K.square(final-base)) # square error | |
def gram_matrix(x): | |
features = K.batch_flatten(x) #flatten -> converts multidimension matrix to single dimensional array | |
gram = K.dot(features,K.transpose(features)) | |
return gram | |
def style_loss(style,final): | |
s = gram_matrix(style) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b_img = K.variable(preprocess_img(base_path)) | |
r_img = K.variable(preprocess_img(ref_path)) | |
final_img = K.placeholder((1,3,img_nrows,img_ncols)) | |
input_tensor = K.concatenate([b_img, r_img, final_img],axis=0) | |
model = vgg16.VGG16(input_tensor=input_tensor,weights='imagenet',include_top=False) | |
output_dict = dict([(layer.name,layer.output) for layer in model.layers]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def preprocess_img(path): | |
print "preprocess: " + path | |
i = load_img(path,target_size=(img_nrows,img_ncols)) | |
i = img_to_array(i) | |
i = np.expand_dims(i,axis=0) | |
i = vgg16.preprocess_input(i) | |
return i | |
def deprocess_img(i): | |
i = i.reshape((3,img_nrows,img_ncols)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
from scipy.optimize import fmin_l_bfgs_b | |
from scipy.misc import imsave, imread, imresize | |
from keras.applications import vgg16 | |
from keras.preprocessing.image import load_img, img_to_array | |
from keras import backend as K | |
import time | |
import numpy as np |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[global] | |
floatX = float32 | |
device = gpu | |
[lib] | |
cnmem = 0 | |
[dnn] | |
enabled = auto |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"image_dim_ordering": "th", | |
"epsilon": 1e-07, | |
"floatx": "float32", | |
"backend": "theano" | |
} |