def Deepdream(self, base_img, iter_n=10, octave_n=4, octave_scale=1.4, clip=True):
# prepare base images for all octaves
octaves = [self.Preprocess(base_img)]
for i in xrange(octave_n-1):
# shrink the image octave[0] so that function always return image size as octave[0]
octaves.append(nd.zoom(octaves[-1], (1, 1.0/octave_scale,1.0/octave_scale), order=1))
src = self.net.blobs['data']
detail = np.zeros_like(octaves[-1]) # allocate image for network-produced details
for octave, octave_base in enumerate(octaves[::-1]):# from end to 0
h, w = octave_base.shape[-2:]
if octave > 0:
# upscale details from the previous octave
h1, w1 = detail.shape[-2:]
detail = nd.zoom(detail, (1, 1.0*h/h1,1.0*w/w1), order=1)
src.reshape(1,3,h,w) # resize the network's input image size
src.data[0] = octave_base+detail
for i in xrange(iter_n):
self.Make_step()
# visualization
'''
vis = self.deprocess(net, src.data[0])
if not clip: # adjust image contrast if clipping is disabled
vis = vis*(255.0/np.percentile(vis, 99.98))
showarray(vis)
print octave, i, end, vis.shape
clear_output(wait=True)
'''
# extract details produced on the current octave
#print octave, self.end, src.data[0].shape
detail = src.data[0]-octave_base
# returning the resulting image
return self.Deprocess(src.data[0])
评论列表
文章目录