Пример #1
0
    def test_non_serialisable(self):
        class NonSerialisableObject(object):
            def __init__(self):
                self.a = 1

        obj = NonSerialisableObject()

        with self.assertRaises(TypeError):
            msgpack.dumps(obj)

        with self.assertRaises(TypeError):
            json.dumps(obj)
Пример #2
0
    def test_datetime(self):
        obj = datetime(2013, 3, 27, 23, 5)
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj == mobj
        assert obj == jobj

        eastern = pytz.timezone('US/Eastern')
        obj = datetime(2013, 3, 27, 23, 5, tzinfo=eastern)
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj == mobj
        assert obj == jobj
Пример #3
0
    def test_date(self):
        obj = date(2013, 3, 27)
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj == mobj
        assert obj == jobj
Пример #4
0
    def on_post(self, req, resp):
        category_to_look_for = req.get_param('catToLookFor')
        print('category to look for:' + str(category_to_look_for))
        ret = {"success": False}
        try:
            data = msgpack.loads(req.stream.read())
            img = data.get("image")
        except Exception:
            ret["error"] = traceback.format_exc()
        try:
            mnc_mask, mnc_box, im, im_name, orig_im, boxes, scalefactor, superimpose_name = mnc.mnc_pixlevel_detect(
                img)
            #            mnc_mask, mnc_box = mnc.mnc_pixlevel_detect(img)
            if mnc_mask is not None:
                ret["success"] = True
                ret['mnc_output'] = {
                    "mask": mnc_mask,
                    "box": mnc_box,
                    "superimposed_image": im,
                    "image_name": im_name,
                    "original_image": orig_im,
                    "bounding_boxes": boxes,
                    "scale_factor": scalefactor
                }

        except Exception:
            ret["error"] = traceback.format_exc()

        resp.data = msgpack.dumps(ret)
        resp.content_type = 'application/x-msgpack'
        resp.status = falcon.HTTP_200
Пример #5
0
    def on_post(self, req, resp):
        t1 = time()
        category = req.get_param('category')
        col_name = req.get_param('col_name')
        ret = {"success": False}
        key = col_name + '.' + category
        forest_handle = self.forests[key]
        try:
            data = msgpack.loads(req.stream.read())
            fp = data.get("fingerprint")

            ret['id_list'] = forest_handle.get_nns_by_vector(fp, 1000)
            if ret["id_list"] is not None:
                ret["success"] = True
            else:
                ret["error"] = "No list"

        except Exception as e:
            ret["error"] = str(e)
        t2 = time()
        duration = t2 - t1
        ret['duration'] = duration
        resp.data = msgpack.dumps(ret)
        resp.content_type = 'application/x-msgpack'
        resp.status = falcon.HTTP_200
Пример #6
0
def pd(image_arrary_or_url):
    data = msgpack.dumps({"image": image_arrary_or_url})
    resp = requests.post(CLASSIFIER_ADDRESS, data)
    if 200 <= resp.status_code < 300:
        return msgpack.loads(resp.content)
    else:
        raise Exception('PD FAILED', resp.content)
Пример #7
0
def nd(image_array_or_url,
       category_index=None,
       get_multilabel_results=None,
       get_combined_results=None,
       get_layer_output=None,
       get_all_graylevels=None,
       threshold=None):
    params = {}
    if category_index:
        params['categoryIndex'] = category_index
    if get_multilabel_results:
        params['getMultilabelResults'] = get_multilabel_results
    if get_combined_results:
        params['getCombinedResults'] = get_combined_results
    if get_layer_output:
        params['getLayerOutput'] = get_layer_output
    if get_all_graylevels:
        params['getAllGrayLevels'] = get_all_graylevels
    if threshold:
        params['threshold'] = threshold


#    if get_yolo:
#        params['getYolo'] = get_yolo
    if params == {}:
        params = None  #not sure if this is necesary but the original line (below) made it happen
        #params = params={"categoryIndex": category_index} if category_index else None
    print('params coming into neurodoll falcon client:' + str(params))
    data = msgpack.dumps({"image": image_array_or_url})
    resp = requests.post(CLASSIFIER_ADDRESS, data=data, params=params)
    return msgpack.loads(resp.content)
Пример #8
0
def sleeve_distance(main_vector, candidate_vector):
    data = msgpack.dumps({
        "function": "distance",
        'main_vector': main_vector,
        'candidate_vector': candidate_vector
    })
    resp = requests.post(CLASSIFIER_ADDRESS, data=data)
    return msgpack.loads(resp.content)
Пример #9
0
def labelize(image_or_url):
    try:
        data = msgpack.dumps({"image": image_or_url})
        resp = requests.post(LABEL_ADDRESS, data)
        labels = msgpack.loads(resp.content)["labels"]
        return {key: float(val) for key, val in labels.items()}
    except:
        return []
Пример #10
0
    def test_int(self):
        obj = 1
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj == mobj
        assert isinstance(mobj, int)
        assert obj == jobj
        assert isinstance(jobj, int)
Пример #11
0
    def test_complex(self):
        obj = complex(123)
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj == mobj
        assert isinstance(mobj, complex)
        assert obj == jobj
        assert isinstance(jobj, complex)
Пример #12
0
    def test_set(self):
        obj = set([1, 2, 3])
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj == mobj
        assert isinstance(mobj, set)
        assert obj == jobj
        assert isinstance(jobj, set)
Пример #13
0
    def test_float(self):
        obj = 3.14159
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj == mobj
        assert isinstance(mobj, float)
        assert obj == jobj
        assert isinstance(jobj, float)
Пример #14
0
    def test_str(self):
        obj = "abc"
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj == mobj
        assert isinstance(mobj, (str, unicode))
        assert obj == jobj
        assert isinstance(jobj, (str, unicode))
Пример #15
0
def detect(img_arr, roi=[]):
    print('using addr ' + str(CLASSIFIER_ADDRESS))
    data = {"image": img_arr}
    if roi:
        print "Make sure roi is a list in this order [x1, y1, x2, y2]"
        data["roi"] = roi
    serialized_data = msgpack.dumps(data)
    resp = requests.post(CLASSIFIER_ADDRESS, data=serialized_data)
    return msgpack.loads(resp.content)
Пример #16
0
    def test_list(self):
        obj = [1, 2, 3]
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj == mobj
        assert isinstance(mobj, list)
        assert obj == jobj
        assert isinstance(jobj, list)
Пример #17
0
    def test_dict(self):
        obj = {'a': 1, 'b': 2, 'c': 3}
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj == mobj
        assert isinstance(mobj, dict)
        assert obj == jobj
        assert isinstance(jobj, dict)
Пример #18
0
    def test_dict_int_keys(self):
        obj = {1: 1, 2: 2, 3: 3}
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj == mobj
        assert isinstance(mobj, dict)
        # we cannot test this as JSON will convert int keys to strings
        #assert obj == jobj
        assert isinstance(jobj, dict)
Пример #19
0
def mnc(image_array_or_url, cat_to_look_for='person'):
    params = {}
    if cat_to_look_for:
        params['catToLookFor'] = cat_to_look_for
    if params == {}:
        params = None  #not sure if this is necesary but the original line (below) made it happen
        #params = params={"categoryIndex": category_index} if category_index else None
    print('params coming into mnc falcon client:' + str(params))
    data = msgpack.dumps({"image": image_array_or_url})
    resp = requests.post(CLASSIFIER_ADDRESS, data=data, params=params)
    return msgpack.loads(resp.content)
def mlb(image_array_or_url, gpu=0):
    params = {}
    if gpu:
        params['gpu'] = gpu
    if params == {}:
        params = None #not sure if this is necesary but the original line (below) made it happen
        #params = params={"categoryIndex": category_index} if category_index else None
    print('params coming into mlb:'+str(params))
    #print('image coming into mlb:'+str(image_array_or_url))
    data = msgpack.dumps({"image": image_array_or_url})
    resp = requests.post(CLASSIFIER_ADDRESS, data=data, params=params)
    return msgpack.loads(resp.content)
Пример #21
0
    def test_serialisable(self):
        class SerialisableObject(jaweson.Serialisable):
            def __init__(self):
                self.a = 1

        obj = SerialisableObject()
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj.a == 1
        assert obj.a == mobj.a
        assert obj.a == jobj.a
Пример #22
0
    def test_serialisable_constructor(self):
        class SerialisableConstructorObject(jaweson.Serialisable):
            def __init__(self, a):
                self.a = a

        obj = SerialisableConstructorObject(2)
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj.a == 2
        assert obj.a == mobj.a
        assert obj.a == jobj.a
Пример #23
0
    def test_npgeneric(self):
        obj = np.float32(1)
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj.dtype == np.float32
        assert obj == mobj
        assert obj.dtype == mobj.dtype
        assert isinstance(mobj, np.generic)
        assert obj == jobj
        assert obj.dtype == jobj.dtype
        assert isinstance(jobj, np.generic)
Пример #24
0
    def test_ndarray(self):
        obj = np.array([1, 2, 3], dtype=np.float32)
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj.dtype == np.float32
        assert (obj == mobj).all()
        assert obj.dtype == mobj.dtype
        assert isinstance(mobj, np.ndarray)
        assert (obj == jobj).all()
        assert obj.dtype == jobj.dtype
        assert isinstance(jobj, np.ndarray)
Пример #25
0
def detect_hls(img_arr, roi=[]):
    print('using addr ' + str(YOLO_HLS_ADDRESS))
    data = {"image": img_arr}
    if roi:
        print "Make sure roi is a list in this order [x1, y1, x2, y2]"
        data["roi"] = roi
    serialized_data = msgpack.dumps(data)
    #    resp = requests.post(YOLO_HLS_ADDRESS, data=data)
    resp = requests.post(YOLO_HLS_ADDRESS, data=serialized_data)
    print('resp from hls:' + str(resp))
    #  print('respcont from hls:'+str(resp.content))
    return msgpack.loads(resp.content)
Пример #26
0
 def on_put(self, req, resp):
     ret = {"success": False}
     try:
         data = msgpack.loads(req.stream.read())
         collection_name = data.get("collection")
         category = data.get("category")
         rebuild_index(collection_name, category)
         ret["success"] = True
     except Exception as e:
         ret["error"] = str(e)
     resp.data = msgpack.dumps(ret)
     resp.content_type = 'application/x-msgpack'
     resp.status = falcon.HTTP_200
Пример #27
0
    def on_post(self, req, resp):
        ret = {"success": False}
        try:
            data = msgpack.loads(req.stream.read())
            ret["data"] = self.feature.execute(**data)
            ret["success"] = True
            resp.status = falcon.HTTP_200
        except Exception as e:
            ret["error"] = str(e)
            ret["trace"] = traceback.format_exc()

        resp.data = msgpack.dumps(ret)
        resp.content_type = 'application/x-msgpack'
Пример #28
0
    def test_class_variable(self):
        class ClassVariableObject(jaweson.Serialisable):
            __classname = 'TestImHere'
            a = 1

        obj = ClassVariableObject()
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj.a == 1
        assert obj.a == mobj.a
        assert obj.a == jobj.a

        assert '_Serialisable__a' not in json.dumps(obj)
Пример #29
0
 def on_post(self, req, resp):
     ret = {"success": False}
     try:
         data = msgpack.loads(req.stream.read())
         collection = data.get("collection")
         category = data.get("category")
         fp = data.get("fp")
         port = lookup_table[collection][category]['port']
         print(port)
         ret = nmslib_find_top_k(fp, 1000, port, category)
         print('done')
     except Exception as e:
         ret["error"] = str(e)
     resp.data = msgpack.dumps(ret)
     resp.content_type = 'application/x-msgpack'
     resp.status = falcon.HTTP_200
Пример #30
0
    def test_modified_class_variable(self):
        class ClassVariableOverrideObject(jaweson.Serialisable):
            a = 1

            def __init__(self):
                self.a = 2

        obj = ClassVariableOverrideObject()
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj.a == 2
        assert obj.a == mobj.a
        assert obj.a == jobj.a

        assert '_Serialisable__a' not in json.dumps(obj)
        assert 'a' in json.dumps(obj)
Пример #31
0
    def test_dodgy_constructor(self):
        class DodgyConstructor(jaweson.Serialisable):
            def __init__(self, a, b):
                # flip the order
                self.a = b
                self.b = a

        obj = DodgyConstructor(1, 2)
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj.a == 2
        assert obj.b == 1
        assert obj.a == mobj.a
        assert obj.b == mobj.b
        assert obj.a == jobj.a
        assert obj.b == jobj.b
Пример #32
0
    def on_post(self, req, resp):
        ret = {"success": False}
        try:
            data = msgpack.loads(req.stream.read())
            image = data.get("image_or_url")
            face = data.get("face")
            print('gender_app nEURALrESOURCE got face {}'.format(face))
            ret["gender"] = new_genderDetector.theDetector(image, face)
            if ret["gender"] is not None:
                ret["success"] = True
            else:
                ret["error"] = "NN returned None, FACE=" + str(face)
                ret["face"] = face
        except Exception as e:
            ret["error"] = str(e)

        resp.data = msgpack.dumps(ret)
        resp.content_type = 'application/x-msgpack'
        resp.status = falcon.HTTP_200
Пример #33
0
    def test_hierarchy(self):
        class Node(jaweson.Serialisable):
            def __init__(self, name, child=None):
                self.name = name
                self.child = child

        obj = Node(1, Node(2, Node(3)))
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj.name == 1
        assert obj.child.name == 2
        assert obj.child.child.name == 3
        assert isinstance(obj, Node)

        assert obj.name == mobj.name
        assert obj.child.name == mobj.child.name
        assert obj.child.child.name == mobj.child.child.name
        assert obj.name == jobj.name
        assert obj.child.name == jobj.child.name
        assert obj.child.child.name == jobj.child.child.name
Пример #34
0
    def on_post(self, req, resp):
        ret = {"success": False}
        try:
            data = msgpack.loads(req.stream.read())

            img = data.get("image")

            # mask_np, label_dict, pose_np, filename
            ret["mask"], ret["label_dict"], ret["pose"], ret[
                "filename"] = new_pd.parse(img, _eng=eng)
            if ret["mask"] is not None:
                ret["success"] = True
            else:
                ret["error"] = "No mask from PD"

        except Exception as e:
            ret["error"] = str(e)

        resp.data = msgpack.dumps(ret)
        resp.content_type = 'application/x-msgpack'
        resp.status = falcon.HTTP_200
Пример #35
0
    def on_post(self, req, resp):
        print "Reached on_post"
        gpu = req.get_param('gpu')
        ret = {"success": False}

        try:
            data = msgpack.loads(req.stream.read())
            img = data.get("image")

            output = multilabel_from_binaries3.get_multiple_single_label_outputs(img)
            ret["output"] = output
            if ret["output"] is not None:
                ret["success"] = True
            else:
                ret["error"] = "No output from mlb"

        except Exception as e:
            traceback.print_exc()
            ret["error"] = traceback.format_exc()

        resp.data = msgpack.dumps(ret)
        resp.content_type = 'application/x-msgpack'
        resp.status = falcon.HTTP_200
Пример #36
0
    def test_custom_serialiser(self):
        class CustomSerialiserObject(jaweson.Serialisable):
            @classmethod
            def to_json(cls, obj):
                return {'c': obj.a, 'd': obj.b}

            @classmethod
            def from_json(cls, obj):
                return cls(int(obj['c']), int(obj['d']))

            def __init__(self, a, b):
                self.a = a
                self.b = b

        obj = CustomSerialiserObject(1, 2)
        mobj = msgpack.loads(msgpack.dumps(obj))
        jobj = json.loads(json.dumps(obj))

        assert obj.a == 1
        assert obj.b == 2
        assert obj.a == mobj.a
        assert obj.b == mobj.b
        assert obj.a == jobj.a
        assert obj.b == jobj.b
Пример #37
0
def secure_the_homeland(image_array_or_url, gpu=1):
    params = {}
    if gpu:
        params['gpu'] = gpu
    if params == {}:
        params = None  #not sure if this is necesary but the original line (below) made it happen
        #params = params={"categoryIndex": category_index} if category_index else None
    print('params coming into hls:' + str(params))

    #try POST
    # #   data = msgpack.dumps({"image": image_array_or_url})
    #    data_dict = {"image": image_array_or_url}
    #    dumped_data = json.dumps(data_dict)
    #    print('secure_the_homeland looking for a response to POST from '+str(FRCNN_CLASSIFIER_ADDRESS))
    #    print('data: '+str(data_dict))
    #    resp = requests.post(FRCNN_CLASSIFIER_ADDRESS, data=dumped_data)
    #    print('response  to POST:'+str(resp.content))
    #    print resp.content

    #try GET with dictionary
    data_dict = {"imageUrl": image_array_or_url}
    print('secure_the_homeland looking for a response to GET w dict from ' +
          str(FRCNN_CLASSIFIER_ADDRESS))
    print('params: ' + str(data_dict))
    resp = requests.get(FRCNN_CLASSIFIER_ADDRESS, params=data_dict)
    print('response  to GET:' + str(resp.content))
    print resp.content

    #try GET with json dumped dictionary
    try_json_dumps = False
    if (try_json_dumps):
        data_dict = {"imageUrl": image_array_or_url}
        dumped_data = json.dumps(data_dict)
        print(
            'secure_the_homeland looking for a response to GET w dumped dict from '
            + str(FRCNN_CLASSIFIER_ADDRESS))
        print('params: ' + str(data_dict))
        resp = requests.get(FRCNN_CLASSIFIER_ADDRESS, params=dumped_data)
        print('response  to GET:' + str(resp.content))
        print resp.content

    #try POST msgpack

#
# data_dict = {"image": image_array_or_url}
# dumped_data = msgpack.dumps(data_dict)
# print('secure_the_homeland looking for a response to POST from '+str(FRCNN_CLASSIFIER_ADDRESS))
# print('data: '+str(data_dict))
# resp = requests.post(FRCNN_CLASSIFIER_ADDRESS, data=dumped_data)
# print('response  to POST:'+str(resp.content))
# print resp.content

#try GET msgpack
    try_msgpack = False
    if (try_msgpack):
        data_dict = {"imageUrl": image_array_or_url}
        dumped_data = msgpack.dumps(data_dict)
        print(
            'secure_the_homeland looking for a response to GET with msgpacked dict from '
            + str(FRCNN_CLASSIFIER_ADDRESS))
        print('params: ' + str(data_dict))
        resp = requests.get(FRCNN_CLASSIFIER_ADDRESS, params=dumped_data)
        print('response  to GET:' + str(resp.content))
        print resp.content
Пример #38
0
def get_length(image_or_url):
    data = msgpack.dumps({"image_or_url": image_or_url})
    resp = requests.post(CLASSIFIER_ADDRESS, data=data)
    return msgpack.loads(resp.content)
Пример #39
0
def genderize(image_or_url, face):
    data = msgpack.dumps({"image_or_url": image_or_url, "face": face})
    resp = requests.post(GENDER_ADDRESS, data)
    return msgpack.loads(resp.content)
Пример #40
0
    def on_post(self, req, resp):
        print "Reached on_post"
        ret = {"success": False}

        try:
##            data = msgpack.loads(req.stream.read())
#            img = data.get("image")
            print('in try of onpost')
            data = json.loads(req.stream.read())
            print('data recd:'+str(data))

            filename = data["filename"]
            img_string = data["img_string"]
            try:
                taggername = data["strUser"]
            except:
                taggername = "unknown"
                print('strUser not sent from webtool')
            imagedata = img_string.split(',')[-1].decode('base64')
            print('filename {} tagger {}'.format(filename,taggername))
            #save new mask under old name and send to extremeli
#            with open(filename, 'wb') as f:
#                f.write(imagedata)
#                f.close()
#            command_string = 'scp '+filename+' [email protected]:/var/www/js-segment-annotator/data/pd_output'
#            subprocess.call(command_string, shell=True)

            #save new mask with 'finished_mask' filename and send to extremeli
            outfilename = filename.replace('.png','_finished_mask.png').replace('.bmp','_finished_mask.bmp').replace('\n','')
#            outfilename = outfilename.replace('_finished_mask','_finished_mask_'+taggername)
            outfile2 = outfilename.replace('_finished_mask.png','_finished_mask_'+taggername+'.txt')
            print('writing r-only img to '+outfilename)
            with open(outfilename, 'wb') as f:
                f.write(imagedata)
                f.close()
            with open(outfile2, 'w') as f:
                f.write(taggername)
                f.close()
            command_string = 'scp '+outfilename+' [email protected]:/var/www/js-segment-annotator/data/pd_output'
            subprocess.call(command_string, shell=True)
            command_string = 'scp '+outfile2+' [email protected]:/var/www/js-segment-annotator/data/pd_output'
            subprocess.call(command_string, shell=True)


            #convert from 'webtool' format (index in red channel of 3chan img) to 'regular' format - 1 chan img that
            #cv2 reads in as 3chan with identical info in all chans
            #then send to extremeli. remove 'webtool' from name, as now its regular format
            img_arr = cv2.imread(outfilename)
            h,w = img_arr.shape[0:2]
            data = img_arr
            if len(img_arr.shape) == 3:
                data = img_arr[:,:,2]
            outfilename = filename.replace('.png','_finished_mask.png').replace('_webtool','').replace('.bmp','_finished_mask.bmp')
            print('writing rgb img to '+outfilename)
            cv2.imwrite(outfilename,data)
            command_string = 'scp '+outfilename+' [email protected]:/var/www/js-segment-annotator/data/pd_output'
            subprocess.call(command_string, shell=True)


            ret["output"] = imagedata
            if ret["output"] is not None:
                ret["success"] = True
            else:
                ret["error"] = "No output from onpost"

        except Exception as e:
            traceback.print_exc()
            ret["error"] = traceback.format_exc()

        resp.data = msgpack.dumps(ret)
        resp.content_type = 'application/x-msgpack'
        resp.status = falcon.HTTP_200
Пример #41
0
#this is doing a post, which the javascript is doing , so I don't think
#we need this file at all...


from jaweson import msgpack
import requests

#
CLASSIFIER_ADDRESS = "http://169.45.147.210:8083/pixlevel_annotator"
#thats brainim60

    params = {}
    if params == {}:
        params = None #not sure if this is necesary but the original line (below) made it happen
        #params = params={"categoryIndex": category_index} if category_index else None
    print('params coming into mlb:'+str(params))
    #print('image coming into mlb:'+str(image_array_or_url))
    data = msgpack.dumps({"image": image_array_or_url})
    resp = requests.post(CLASSIFIER_ADDRESS, data=data, params=params)
    return msgpack.loads(resp.content)
    
Пример #42
0
def get(feature, image_or_url, **kwargs):
    kwargs.update({"image_or_url": image_or_url})
    data = msgpack.dumps(kwargs)
    resp = requests.post(DEPLOYMENTS[feature]["url"], data=data)
    return msgpack.loads(resp.content)
Пример #43
0
    def on_post(self, req, resp):
        print "Reached on_post"

        ret = {"success": False}

        # Query Params
        threshold = req.get_param('threshold')
        get_multilabel_results = req.get_param_as_bool('getMultilabelResults')
        get_combined_results = req.get_param_as_bool('getCombinedResults')

        image_url = req.get_param('imageUrl')

        try:
            if image_url:
                img = image_url  # Utils.get_cv2_img_array(image_url)
            else:
                data = msgpack.loads(req.stream.read())
                img = data.get("image")

            # multilabel alone
            if get_multilabel_results:
                multilabel_output = neurodoll.get_multilabel_output(img)
                ret['multilabel_output'] = multilabel_output
                print('multilabel output:' + str(multilabel_output))
                if multilabel_output is not None:
                    ret["success"] = True
                # ret["success"] = bool(multilabel_output)

            # combined multilabel and nd
            if get_combined_results:
                combined_output = None
                combined_output = neurodoll.combine_neurodoll_v3labels_and_multilabel(
                    img)
                ret['combined_output'] = combined_output
                ret['mask'] = combined_output
                if combined_output is not None:
                    ret["bbs"] = imutils.mask_to_rects(ret['mask'])
                    ret["success"] = True

            # yonti style - single category mask
            ret["label_dict"] = constants.ultimate_21_dict

            # regular neurodoll call
            if not get_multilabel_results and not get_combined_results and not category_index:
                print "No special params, inferring..."
                ret["mask"], labels = neurodoll.infer_one(img)
                if ret["mask"] is not None:
                    ret["success"] = True
                    ret["bbs"] = imutils.mask_to_rects(ret["mask"])
                else:
                    ret["error"] = "No mask from ND"

        except Exception as e:
            traceback.print_exc()
            ret["error"] = traceback.format_exc()
            url = req.get_param('image')
            ret['url'] = url
        resp.data = msgpack.dumps(ret)
        resp.content_type = 'application/x-msgpack'
        resp.status = falcon.HTTP_200
        return (ret)
Пример #44
0
def get_sleeve(image_or_url):
    data = msgpack.dumps({"function": "execute", "image_or_url": image_or_url})
    resp = requests.post(CLASSIFIER_ADDRESS, data=data)
    return msgpack.loads(resp.content)
Пример #45
0
def pd(fp, col_name, category):
    params = {"category": category,
              "col_name" : col_name}
    data = msgpack.dumps({"fingerprint": fp})
    resp = requests.post(CLASSIFIER_ADDRESS, data=data, params=params)
    return msgpack.loads(resp.content)
Пример #46
0
def nmslib_find_top_k(fp, k, port, category):
    data = msgpack.dumps({"fp": fp, "k": k})
    category_server = SERVER + str(port) + '/' + category
    resp = requests.post(category_server, data=data)
    return msgpack.loads(resp.content)
Пример #47
0
    f, enc_np = cv2.imencode('.png', arr, [cv2.IMWRITE_PNG_COMPRESSION, 9])
    return msgpack.dumps(enc_np)


def deserialize(msg):
    enc_np = msgpack.loads(msg)
    return cv2.imdecode(enc_np, cv2.IMREAD_COLOR)


arr_cv2 = url_to_np_array(
    "http://fazz.co/src/img/demo/gettyimages-492504614.jpg")
f, enc_jpg_np = cv2.imencode('.jpg', arr_cv2, [cv2.IMWRITE_JPEG_QUALITY, 100])
f, enc_png_np = cv2.imencode('.png', arr_cv2, [cv2.IMWRITE_PNG_COMPRESSION, 9])

start = time.time()
msg = msgpack.dumps(arr_cv2)
arr = msgpack.loads(msg)
print time.time() - start

start = time.time()
msg = msgpack.dumps(
    cv2.imencode('.png', arr_cv2, [cv2.IMWRITE_PNG_COMPRESSION, 9])[1])
arr = cv2.imdecode(msgpack.loads(msg), cv2.IMREAD_COLOR)
print time.time() - start


def data_uri_to_cv2_img(uri):
    encoded_data = uri.split(',')[1]
    nparr = np.fromstring(encoded_data.decode('base64'), np.uint8)
    img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
    return img
Пример #48
0
def serialize(arr):
    f, enc_np = cv2.imencode('.png', arr, [cv2.IMWRITE_PNG_COMPRESSION, 9])
    return msgpack.dumps(enc_np)