I'm trying to obtain new image while combing two different ones, for style transfer. I have two images (one is the target and the other is the style). And I want to get new one from the two of them.
target_image = K.constant(preprocess_image(target_image_path))
style_reference_image = K.constant(preprocess_image(style_image_path))
combination_image = K.placeholder((1, img_height, img_width, 3))
When I want to use the combinatin_image in this function:
grads = K.gradients(loss, combination_image)[0]
fetch_loss_and_grads = K.function([combination_image], [loss, grads])
class Evaluator(object):
def __init__(self):
self.loss_value = None
self.grads_values = None
def loss(self, x):
assert self.loss_value is None
x = x.reshape((1, img_height, img_width, 3))
outs = fetch_loss_and_grads([x])
loss_value = outs[0]
grad_values = outs[1].flatten().astype('float64')
self.loss_value = loss_value
self.grad_values = grad_values
return self.loss_value
def grads(self, x):
assert self.loss_value is not None
grad_values = np.copy(self.grad_values)
self.loss_value = None
self.grad_values = None
return grad_values
evaluator = Evaluator()
x = preprocess_image(target_image_path)
x = x.flatten()
for i in range(iterations):
x, min_val, info = fmin_l_bfgs_b(evaluator.loss, x,
fprime=evaluator.grads, maxfun=20)
I'm dealing with an error 'NoneType' object has no attribute 'type'.
I tried changing the combinatin_image (combination_image = preprocess_image(new_image_path)) but thet I have a new error:
---->5 fetch_loss_and_grads = K.function([combination_image], [loss, grads])
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/backend.py in __init__(self, inputs, outputs, updates, name)
3681 'of elements from multiple graphs.')
3682
-> 3683 source_graph = graphs.pop()
3684 global_graph = get_graph()
3685
KeyError: 'pop from an empty set'