- We have to first pre process the image to be able to work with the pre processed network. (Basically converts it into the format inception was trained)
- We then convert it into a tensor and split the execution into parts
- We simply use the deepdream function to calculate the losses
- We use the deprocess function to convert it back into an image from a tensor
- clear_output is just a function to make sure the notebook doesnt get flooded with outputs and only the latest output is kept
def run_deep_dream_simple(img, steps=100, step_size=0.01):
img = tf.keras.applications.inception_v3.preprocess_input(img)
img = tf.convert_to_tensor(img)
step_size = tf.convert_to_tensor(step_size)
steps_remaining = steps
step = 0
while steps_remaining:
if steps_remaining > 100:
run_steps = tf.constant(100)
else:
run_steps = tf.constant(steps_remaining)
steps_remaining -= run_steps
step += run_steps
loss, img = deepdream(img, run_steps, tf.constant(step_size))
display.clear_output(wait=True)
show(deprocess(img))
print("Step {}, loss {}".format(step, loss))
result = deprocess(img)
display.clear_output(wait=True)
show(result)
return result
dream_img = run_deep_dream_simple(img=original_img, steps=100, step_size=0.01)