Exemple #1
0
 def load_model(self, cnn_feature_extractor):
     if os.path.exists(cnn_feature_extractor):
         app_logger.info("loading... {}".format(cnn_feature_extractor))
         self.feature_extractor = pickle.load(open(cnn_feature_extractor))
         app_logger.info("done")
     else:
         self.feature_extractor = CnnFeatureExtractor(self.use_gpu, self.model, self.model_type,
                                                      self.image_feature_dim)
         pickle.dump(self.feature_extractor, open(cnn_feature_extractor, 'w'))
         app_logger.info("pickle.dump finished")
    def __init__(self, **kwargs):
        if os.path.exists(CNN_FEATURE_EXTRACTOR):
            app_logger.info("loading... {}".format(CNN_FEATURE_EXTRACTOR))
            self.feature_extractor = pickle.load(open(CNN_FEATURE_EXTRACTOR))
            app_logger.info("done")
        else:
            self.feature_extractor = CnnFeatureExtractor(use_gpu, CAFFE_MODEL, MODEL_TYPE, image_feature_dim)
            pickle.dump(self.feature_extractor, open(CNN_FEATURE_EXTRACTOR, 'w'))
            app_logger.info("pickle.dump finished")

        self.agent_service = AgentService(BRICA_CONFIG_FILE, self.feature_extractor)
        self.result_logger = ResultLogger()
Exemple #3
0
class VVCComponent(brica1.Component):
    image_feature_count = 1
    cnn_feature_extractor = CNN_FEATURE_EXTRACTOR
    model = CAFFE_MODEL
    model_type = MODEL_TYPE
    image_feature_dim = 256 * 6 * 6

    def __init__(self, n_output=10240, n_input=1):
        # image_feature_count = 1
        super(VVCComponent, self).__init__()

        self.use_gpu = use_gpu
        self.n_output = n_output
        self.n_input = n_input

    def set_model(self, feature_extractor):
        self.feature_extractor = feature_extractor

    def load_model(self, cnn_feature_extractor):
        if os.path.exists(cnn_feature_extractor):
            app_logger.info("loading... {}".format(cnn_feature_extractor))
            self.feature_extractor = pickle.load(open(cnn_feature_extractor))
            app_logger.info("done")
        else:
            self.feature_extractor = CnnFeatureExtractor(self.use_gpu, self.model, self.model_type,
                                                         self.image_feature_dim)
            pickle.dump(self.feature_extractor, open(cnn_feature_extractor, 'w'))
            app_logger.info("pickle.dump finished")

    def fire(self):
        observation = self.get_in_port('Isocortex#V1-Isocortex#VVC-Input').buffer
        obs_array = self.feature_extractor.feature(observation, self.image_feature_count)

        self.results['Isocortex#VVC-BG-Output'] = obs_array
        self.results['Isocortex#VVC-UB-Output'] = obs_array
class Root(object):
    def __init__(self, **kwargs):
        if os.path.exists(CNN_FEATURE_EXTRACTOR):
            app_logger.info("loading... {}".format(CNN_FEATURE_EXTRACTOR))
            self.feature_extractor = pickle.load(open(CNN_FEATURE_EXTRACTOR, 'rb'))
            app_logger.info("done")
        else:
            self.feature_extractor = CnnFeatureExtractor(use_gpu, CAFFE_MODEL, MODEL_TYPE, image_feature_dim)
            pickle.dump(self.feature_extractor, open(CNN_FEATURE_EXTRACTOR, 'wb'))
            app_logger.info("pickle.dump finished")

        self.agent_service = AgentService(BRICA_CONFIG_FILE, self.feature_extractor)
        self.result_logger = ResultLogger()

    @cherrypy.expose()
    def flush(self, identifier):
        self.agent_service.initialize(identifier)

    @cherrypy.expose
    def create(self, identifier):
        body = cherrypy.request.body.read()
        reward, observation, rotation, movement = unpack(body)

        inbound_logger.info('reward: {}, depth: {}'.format(reward, observation['depth']))
        feature = self.feature_extractor.feature(observation)
        self.result_logger.initialize()
        result = self.agent_service.create(reward, feature, identifier)
        self.result_logger.add_agent(self.agent_service.agents[identifier])

        outbound_logger.info('action: {}'.format(result))

        return str(result)

    @cherrypy.expose
    def step(self, identifier):
        body = cherrypy.request.body.read()
        reward, observation, rotation, movement = unpack(body)

        inbound_logger.info('reward: {}, depth: {}'.format(reward, observation['depth']))

        result = self.agent_service.step(reward, observation, identifier)
        self.result_logger.step()
        outbound_logger.info('result: {}'.format(result))
        return str(result)

    @cherrypy.expose
    def reset(self, identifier):
        body = cherrypy.request.body.read()
        reward, success, failure, elapsed, finished = unpack_reset(body)

        inbound_logger.info('reward: {}, success: {}, failure: {}, elapsed: {}'.format(
            reward, success, failure, elapsed))

        result = self.agent_service.reset(reward, identifier)
        self.result_logger.report(success, failure, finished)

        outbound_logger.info('result: {}'.format(result))
        return str(result)