示例#1
0
 def set_endlayer(self, layer_index):
     self.end = self.layers[layer_index]['name']
     self.features = self.layers[layer_index]['features']
     self.current_feature = self.features[0]
     self.log_featuremap()
     self.Renderer.request_wakeup()
     log.warning('layer: {} ({})'.format(self.end, self.net.blobs[self.end].data.shape[1]))
     console.log_value('layer','{} ({})'.format(self.end, self.net.blobs[self.end].data.shape[1]))
示例#2
0
    def choose_model(self, modelname):
        self.net_fn = '{}/{}/{}'.format(models['path'], models[modelname][0], models[modelname][1])
        self.param_fn = '{}/{}/{}'.format(models['path'], models[modelname][0], models[modelname][2])

        model = caffe.io.caffe_pb2.NetParameter()
        text_format.Merge(open(self.net_fn).read(), model)
        model.force_backward = True
        open('tmp.prototxt', 'w').write(str(model))

        magic_numbers = [104.0, 116.0, 122.0]

        self.net = caffe.Classifier('tmp.prototxt',
            self.param_fn, mean=np.float32(magic_numbers),
            # self.param_fn, mean=np.float32([64.0, 480.0, -120.0]),
            # self.param_fn, mean=np.float32([364.0, 20.0, -20.0]),
            # self.param_fn, mean=np.float32([128.0, 168.0, 96.0]),
            channel_swap=(2, 1, 0))

        console.log_value('model', models[modelname][2])
示例#3
0
def main():
    now = time.time()  # start timer
    Composer.start()
    Webcam.get().start()
    iterations = Model.iterations
    stepsize = Model.stepsize_base
    octave_n = Model.octave_n
    octave_scale = Model.octave_scale
    jitter = 300

    # logging
    console.log_value('username',data.username)
    console.log_value('settings',Model.package_name)

    # the madness begins
    initial_image = Webcam.get().read()
    Composer.send(1, initial_image)
    data.playback = initial_image  # initial camera image for starting

    while True:
        log.warning('new cycle')
        _Deepdreamer.set_cycle_start_time(time.time())

        if Model.cyclefx is not None:
            for fx in Model.cyclefx:
                if fx['name'] == 'octave_scaler':
                    Model.octave_scale = round(postprocess.octave_scaler(fx['osc']),4)
                    log.critical('octave_scale: {}'.format(Model.octave_scale))
                if fx['name'] == 'xform_array':
                    postprocess.xform_array(Composer.dreambuffer, **fx['params'])
                if fx['name'] == 'inception_xform':
                    data.playback = postprocess.inception_xform(data.playback, **fx['params'])

        # new rem sleep test
        _Deepdreamer.paint(
            Model=Model,
            base_image=data.playback,
            iteration_max = Model.iterations,
            iteration_mult = Model.iteration_mult,
            octave_n = Model.octave_n,
            octave_cutoff = Model.octave_cutoff,
            octave_scale= Model.octave_scale,
            end = Model.end,
            objective = dreamer.objective_L2,
            stepsize_base = Model.stepsize_base,
            step_mult = Model.step_mult,
            feature = Model.current_feature,
            stepfx = Model.stepfx,
            Webcam=Webcam,
            Composer=Composer,
            Framebuffer = data.Framebuffer
            )

        # logging
        later = time.time()
        duration_msg = '{:.2f}s'.format(later - now)
        now = time.time()  # the new now
        console.log_value('cycle_time',duration_msg)
        log.critical('cycle time: {}\n{}'.format(duration_msg, '-' * 80))
示例#4
0
    def process(self, delta):
        # history
        self.delta = delta

        # scale value to ride peak values & prevent sensitive triggering
        self.delta_trigger = self.add_to_history(self.delta) + self.floor

        lastmsg = '{:0>6}'.format(self.delta_history)
        nowmsg = '{:0>6}'.format(self.delta)
        console.log_value('last', lastmsg)
        console.log_value('now', nowmsg)
        console.log_value('threshold', '{:0>6}'.format(self.delta_trigger))
        console.log_value('floor', '{:0>6}'.format(self.floor))

        #  track delta count history
        self.delta_history = self.delta

        # track peak value
        if self.delta_history > self.delta_history_peak:
            self.delta_history_peak = self.delta_history
        if self.delta < self.floor:
            self.delta_history_peak = 0
        threadlog.warning('history:{}'.format(self.delta_history))
示例#5
0
    def set_program(self, current_program):
        program = performer.program[current_program]
        self.package_name = program['name']
        self.program_start_time = time.time()
        self.current_program = current_program
        self.iterations = program['iterations']
        self.iteration_max = program['iterations']
        self.iteration_mult = program['iteration_mult']
        self.stepsize_base = program['step_size']
        self.step_mult = program['step_mult']
        self.octave_n = program['octaves']
        self.octave_cutoff = program['octave_cutoff']
        self.octave_scale = program['octave_scale']
        self.layers = program['layers']
        self.current_layer = 0
        self.features = None # this will be defined in set_end_layer()
        self.current_feature = 0
        self.jitter = 320
        self.clip = True
        self.modelname = program['model']
        self.choose_model(self.modelname)
        self.set_endlayer(self.current_layer)
        self.stepfx = program['stepfx']
        self.autofeature = program['autofeature']
        self.cyclefx = program['cyclefx']
        self.pool = None
        for fx in self.cyclefx:
            if fx['name'] == 'octave_scaler':
                # self.pool = self.setup_octave_scaler(**value['params'])
                params = fx['params']
                fx['osc'] = postprocess.oscillator(
                    cycle_length = params['cycle_length'],
                    frequency = params['frequency'],
                    range_out = params['range_out'],
                    wavetype = params['wavetype'],
                    dutycycle = params['dutycycle']
                )

        for fx in self.stepfx:
            if fx['name'] == 'median_blur':
                params = fx['params']
                fx['osc'] = postprocess.oscillator(
                    cycle_length = params['cycle_length'],
                    frequency = params['frequency'],
                    range_out = params['range_out'],
                    wavetype = params['wavetype'],
                    dutycycle = params['dutycycle']
                )
            if fx['name'] == 'bilateral_filter':
                params = fx['radius']
                fx['osc1'] = postprocess.oscillator(
                    cycle_length = params['cycle_length'],
                    frequency = params['frequency'],
                    range_out = params['range_out'],
                    wavetype = params['wavetype'],
                    dutycycle = params['dutycycle']
                )
                params = fx['sigma-color']
                fx['osc2'] = postprocess.oscillator(
                    cycle_length = params['cycle_length'],
                    frequency = params['frequency'],
                    range_out = params['range_out'],
                    wavetype = params['wavetype'],
                    dutycycle = params['dutycycle']
                )
                params = fx['sigma-xy']
                fx['osc3'] = postprocess.oscillator(
                    cycle_length = params['cycle_length'],
                    frequency = params['frequency'],
                    range_out = params['range_out'],
                    wavetype = params['wavetype'],
                    dutycycle = params['dutycycle']
                )
            if fx['name'] == 'gaussian':
                params = fx['sigma']
                fx['osc'] = postprocess.oscillator(
                    cycle_length = params['cycle_length'],
                    frequency = params['frequency'],
                    range_out = params['range_out'],
                    wavetype = params['wavetype'],
                    dutycycle = params['dutycycle']
                )
            if fx['name'] == 'step_mixer':
                params = fx['opacity']
                fx['osc'] = postprocess.oscillator(
                    cycle_length = params['cycle_length'],
                    frequency = params['frequency'],
                    range_out = params['range_out'],
                    wavetype = params['wavetype'],
                    dutycycle = params['dutycycle']
                )
            if fx['name'] == 'slowshutter':
                params = fx['samplesize']
                fx['osc1'] = postprocess.oscillator(
                    cycle_length = params['cycle_length'],
                    frequency = params['frequency'],
                    range_out = params['range_out'],
                    wavetype = params['wavetype'],
                    dutycycle = params['dutycycle']
                )
                params = fx['interval']
                fx['osc2'] = postprocess.oscillator(
                    cycle_length = params['cycle_length'],
                    frequency = params['frequency'],
                    range_out = params['range_out'],
                    wavetype = params['wavetype'],
                    dutycycle = params['dutycycle']
                )
            if fx['name'] == 'featuremap':
                params = fx['index']
                fx['osc1'] = postprocess.oscillator(
                    cycle_length = params['cycle_length'],
                    frequency = params['frequency'],
                    range_out = params['range_out'],
                    wavetype = params['wavetype'],
                    dutycycle = params['dutycycle']
                )

        log.warning('program:{} started:{}'.format(program['name'], self.program_start_time))
        console.log_value('program', self.package_name)
        self.Renderer.request_wakeup()
示例#6
0
 def log_featuremap(self):
     max_feature_index = self.net.blobs[self.end].data.shape[1]
     log.critical('feature:{}/{}'.format(self.current_feature,max_feature_index))
     console.log_value('featuremap', self.current_feature)
示例#7
0
    def paint(self,
              Model,
              base_image,
              iteration_max,
              iteration_mult,
              octave_n,
              octave_cutoff,
              octave_scale,
              end,
              objective,
              stepsize_base,
              step_mult,
              feature,
              stepfx,
              Webcam,
              Composer,
              Framebuffer,
              clip=False):

        # # SETUP OCTAVES
        src = Model.net.blobs['data']
        octaves = [data.rgb2caffe(Model.net, base_image)]
        log.warning('octave_n: {}'.format(octave_n))

        if Model.cyclefx is not None:
            for fx in Model.cyclefx:
                if fx['name'] == 'octave_scaler':
                    Model.octave_scale = round(
                        postprocess.octave_scaler(fx['osc']), 4)
                    log.critical('octave_scale: {}'.format(Model.octave_scale))

        for i in xrange(octave_n - 1):
            octaves.append(
                nd.zoom(octaves[-1], (1, round(
                    (1.0 / octave_scale), 2), round((1.0 / octave_scale), 2)),
                        order=1))
        detail = np.zeros_like(octaves[-1])

        step_size = stepsize_base
        for octave, octave_current in enumerate(octaves[::-1]):
            h, w = octave_current.shape[-2:]
            h1, w1 = detail.shape[-2:]
            detail = nd.zoom(detail, (1, 1.0 * h / h1, 1.0 * w / w1), order=0)
            src.reshape(1, 3, h, w)
            src.data[0] = octave_current + detail

            # OCTAVE CYCLE
            i = 1
            while i <= iteration_max:
                if self.was_wakeup_requested():
                    self.clear_request()
                    data.playback = Webcam.get().read()
                    return

                self.make_step(Model=Model,
                               step_size=step_size,
                               end=end,
                               feature=feature,
                               objective=objective,
                               stepfx=stepfx,
                               jitter=200)

                console.log_value(
                    'octave', '{}/{}({})'.format(octave + 1, octave_n,
                                                 octave_cutoff))
                console.log_value(
                    'iteration',
                    '{:0>3}:{:0>3} x{}'.format(i, iteration_max,
                                               iteration_mult))
                console.log_value(
                    'step_size',
                    '{:02.3f} x{:02.3f}'.format(step_size, step_mult))
                console.log_value('width', w)
                console.log_value('height', h)
                console.log_value('scale', octave_scale)

                log.critical('{}/{}({}) {}/{}'.format(octave + 1, octave_n,
                                                      octave_cutoff, i,
                                                      iteration_max))

                vis = data.caffe2rgb(Model.net, src.data[0])
                vis = vis * (255.0 / np.percentile(vis, 99.98))
                data.vis = vis
                step_size += stepsize_base * step_mult
                if step_size < 0.1:
                    step_size = 0.1
                i += 1
                detail = src.data[0] - octave_current
                if octave > octave_cutoff:
                    break
            iteration_max = int(iteration_max -
                                (iteration_max * iteration_mult))

        if self.was_photo_requested():
            self.clear_photo_request()
            data.Viewport.export()
        return
示例#8
0
 def set_gamma(self, gamma):
     # generates internal table for gamma correction
     log.debug('gamma: {}'.format(gamma))
     console.log_value('gamma','{}'.format(gamma))
     return np.array([((i / 255.0) ** (1.0 / gamma)) * 255 for i in
         np.arange(0, 256)]).astype("uint8")