deepdream.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:DeepArt 作者: jiriroz 项目源码 文件源码
def dream(self, base_img, iter_n=10, octave_n=4, octave_scale=1.4, 
                end='inception_4c/output', clip=True, guide_features=None, name="dream", **step_params):
        # prepare base images for all octaves
        octaves = [self.preprocess(base_img)]
        for i in xrange(octave_n-1):
            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]):
            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(end=end, clip=clip, guide_features=guide_features, **step_params)

                # visualization
                vis = self.deprocess(src.data[0])
                # adjust image contrast if clipping is disabled
                if not clip:
                    vis = vis*(255.0/np.percentile(vis, 99.98))
                print octave, i, end, vis.shape
                clear_output(wait=True)

            # extract details produced on the current octave
            detail = src.data[0]-octave_base
        self.showarray(vis, name)
        # returning the resulting image
        return self.deprocess(src.data[0])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号