def takeout_chain_job(self, table, model, input_column, output_column, start_row, stop_row, job_row): model = picarus_takeout.ModelChain(msgpack.dumps(model)) def func(input_data): return model.process_binary(input_data) self._row_job(table, start_row, stop_row, input_column, output_column, func, job_row)
def main(): image_points = ImagePoints() image_match = ImageMatch() match_points = {} ar_model = picarus_takeout.ModelChain( msgpack.dumps([{ 'kw': {}, 'name': 'picarus.ARMarkerDetector' }])) print() def callback(ws, **kw): def image_handler(*data): groupDevice = '' # data[0].split(':', 1)[1] print('Image[%s]' % data[0]) if groupDevice in match_points: st = time.time() pts = image_points(data[2]) print('Points[%f]' % (time.time() - st)) st = time.time() h = image_match(match_points[groupDevice], pts) print('Match[%f]' % (time.time() - st)) print('Sending') ws.publish('warph:' + groupDevice, h.ravel().tolist()) tags, tag_size = msgpack.loads(ar_model.process_binary(data[2])) ws.publish('warptags:image', np.array(tags).reshape(tag_size).tolist()) def warp_sample_handler(*data): print('Warp Sample') match_points[data[1]] = image_points(data[2]) tags, tag_size = msgpack.loads(ar_model.process_binary(data[2])) ws.publish('warptags:sample', np.array(tags).reshape(tag_size).tolist()) ws.subscribe('image', image_handler) ws.subscribe('warpsample', warp_sample_handler) ws.handler_loop() wearscript.parse(callback, argparse.ArgumentParser())
def __init__(self, verbose=False): model = "kYKia3eDqG1heF9kaXN0eKttaW5faW5saWVycwqtcmVwcm9qX3RocmVzaMtAFAAAAAAAAKRuYW1l2gAkcGljYXJ1cy5JbWFnZUhvbW9ncmFwaHlSYW5zYWNIYW1taW5n" self.model = picarus_takeout.ModelChain(base64.b64decode(model)) self.verbose = verbose
def __init__(self, verbose=False): model = "kYKia3eDrXBhdHRlcm5fc2NhbGXLP/AAAAAAAACmdGhyZXNoFKdvY3RhdmVzAqRuYW1lu3BpY2FydXMuQlJJU0tJbWFnZUZlYXR1cmUyZA==" self.model = picarus_takeout.ModelChain(base64.b64decode(model)) self.verbose = verbose
def __init__(self): super(Mapper, self).__init__() self._model = zlib.decompress(open(os.environ['MODEL_FN']).read()) self.job = picarus_takeout.ModelChain(self._model)
def post_row(self, row, params, files): if files: bottle.abort(400, 'Table does not support files') params = dict((k, base64.b64decode(v)) for k, v in params.items()) action = params['action'] with thrift_lock() as thrift: manager = PicarusManager(db=thrift) if action in ('i/link', 'i/chain', 'io/link', 'io/chain'): model_key = params['model'] write_result = action.startswith('io/') if write_result: self._row_validate(row, 'rw') else: self._row_validate(row, 'r') if action.endswith('/link'): chain_input, model_link = _takeout_input_model_link_from_key( manager, model_key) binary_input = thrift.get_column(self.table, row, chain_input) model = picarus_takeout.ModelChain( msgpack.dumps([model_link])) else: chain_inputs, model_chain = zip( *_takeout_input_model_chain_from_key( manager, model_key)) binary_input = thrift.get_column(self.table, row, chain_inputs[0]) model = picarus_takeout.ModelChain( msgpack.dumps(list(model_chain))) bottle.response.headers["Content-type"] = "application/json" model_out = model.process_binary(binary_input) if write_result: thrift.mutate_row(self.table, row, {model_key: model_out}) return json.dumps( {base64.b64encode(model_key): base64.b64encode(model_out)}) elif action in ('io/thumbnail', 'i/thumbnail'): # TODO: Refactor this, it shares code with link/chain write_result = action.startswith('io/') if write_result: self._row_validate(row, 'rw') else: self._row_validate(row, 'r') # Makes 150x150 thumbnails from the data:image column model_chain = [{ 'name': 'picarus.ImagePreprocessor', 'kw': { 'method': 'force_square', 'size': 150, 'compression': 'jpg' } }] model = picarus_takeout.ModelChain( msgpack.dumps(list(model_chain))) bottle.response.headers["Content-type"] = "application/json" model_out = model.process_binary( thrift.get_column(self.table, row, 'data:image')) if write_result: thrift.mutate_row(self.table, row, {'thum:image_150sq': model_out}) return json.dumps({ base64.b64encode('thum:image_150sq'): base64.b64encode(model_out) }) else: bottle.abort(400, 'Invalid parameter value [action]')