generative deep learning original_shape img shape[ : successive_shapes [original_shapefor in range( num_octave)shape tuple([int(dim (octave_scale * )for dim in original_shape]successive_shapes append(shapesuccessive_shapes successive_shapes[::- scales up the dream image prepares list of shape tuples defining the different scales at which to run gradient ascent reverses the list of shapes so they're in increasing order original_img np copy(imgshrunk_original_img resize_img(imgsuccessive_shapes[ ]resizes the numpy for shape in successive_shapesarray of the image print('processing image shape'shapeto the smallest scale img resize_img(imgshapeimg gradient_ascent(imgscales up the smaller iterations=iterationsruns gradient version of the original step=stepascentaltering imageit will be pixellated max_loss=max_lossthe dream upscaled_shrunk_original_img resize_img(shrunk_original_imgshapesame_size_original resize_img(original_imgshapelost_detail same_size_original upscaled_shrunk_original_img img +lost_detail shrunk_original_img resize_img(original_imgshapesave_img(imgfname='dream_at_scale_str(shapepng'save_img(imgfname='final_dream png'reinjects lost detail into the dream computes the high-quality version of the original image at this size the difference between the two is the detail that was lost when scaling up note that this code uses the following straightforward auxiliary numpy functionswhich all do as their names suggest they require that you have scipy installed listing auxiliary funct ions import scipy from keras preprocessing import image def resize_img(imgsize)img np copy(imgfactors ( float(size[ ]img shape[ ]float(size[ ]img shape[ ] return scipy ndimage zoom(imgfactorsorder= def save_img(imgfname)pil_img deprocess_image(np copy(img)scipy misc imsave(fnamepil_imgdef preprocess_image(image_path)img image load_img(image_pathimg image img_to_array(imglicensed to util function to openresizeand format pictures into tensors that inception can process