def setup(self, bottom, top):
        self.top_names = ['img1', 'img2','flow']
        params = eval(self.param_str)
        check_params(params, 
                batch_size=1, 
                split=None, 
                shuffle=True, 
                num_threads = 1, 
                max_queue_size = 1,
                annotation_file = '/mnt/sdc/FlyingChairs_release/FlyingChairs_train_val.txt',
                im_shape = None,
                mean1=np.array([0.411451, 0.432060, 0.450141]),
                mean2=np.array([0.431021, 0.410602, 0.448553]) )
        self.batch_size = params['batch_size']
        self.num_threads = params['num_threads']
        self.max_queue_size = params['max_queue_size']
        self.queue = Queue(self.max_queue_size)
        self.processes = [None]*self.num_threads
        self.netflow_db = load_netflow_db(params['annotation_file'], params['split'], shuffle=params['shuffle'])
        
        for i in range(self.num_threads):
            batch_loader = FlowLoader(params, self.netflow_db)
            self.processes[i] = FlowLoaderProcess(kwargs={'queue':self.queue,'loader':batch_loader})
            self.processes[i].daemon = True
            self.processes[i].start()

        top[0].reshape(
                self.batch_size, 3, params['im_shape'][0],
                params['im_shape'][1]) #NOTE: current is devided by 2
        top[1].reshape(
                self.batch_size, 3, params['im_shape'][0],
                params['im_shape'][1])
        top[2].reshape(
                self.batch_size, 2, params['im_shape'][0],
                params['im_shape'][1])
    def setup(self, bottom, top):
        self.top_names = ['current_image', 'masked_image','next_image','label']
        params = eval(self.param_str)
              
        if not params.has_key('dataset') or params['dataset'] == 'coco':
	    default_cats = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 
			     'bus', 'train', 'truck', 'boat', 'bird', 'cat', 'dog', 
			     'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 
			     'giraffe', 'kite']
	elif params['dataset'] == 'pascal':
	    default_cats = ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 
			       'bus', 'car' , 'cat', 'chair', 'cow',
			       'dog', 'horse', 'motorbike', 'person',
			       'sheep', 'sofa', 'train']

        check_params(params, dataset='coco', batch_size=1, split=None, im_shape=0, shuffle=True, num_threads = 1, max_queue_size = 1, data_dir = '/home/amir/coco',
		     cats = default_cats, areaRng = [1500. , np.inf], iscrowd=False, mean=None, noisy_mask = False, bgr=False, scale_256=False, cur_shape=0, next_shape=0,
		     inverse_flow = False, flow_scale = 1.0, bb1_enlargment = None, bb2_enlargment = None)
		     
	#For backward compatibility
        if params['next_shape'] == 0 or params['cur_shape'] == 0:
	    if params['im_shape'] == 0:
		raise Exception('Either im_shape or (cur_shape, next_shape) parameters should be set')
	    params['next_shape'] = params['im_shape']
	    params['cur_shape'] = [params['im_shape'][0]/2, params['im_shape'][1]/2]

        self.batch_size = params['batch_size']
        self.num_threads = params['num_threads']
        self.max_queue_size = params['max_queue_size']
        self.queue = Queue(self.max_queue_size)
        self.processes = [None]*self.num_threads
        
        if params['dataset'] == 'coco':
	    self.coco_dbs = load_coco_db(params['data_dir'], params['split'], cats=params['cats'], areaRng=params['areaRng'], iscrowd=params['iscrowd'], shuffle=params['shuffle'], chunck_num = self.num_threads)
	elif params['dataset'] == 'pascal':
	    self.coco_dbs = load_pascal_db(params['data_dir'], params['split'], cats=params['cats'], areaRng=params['areaRng'], shuffle=params['shuffle'], chunck_num = self.num_threads)
        
        for i in range(self.num_threads):
            batch_loader = ImagePairLoader(params, self.coco_dbs[i])
            self.processes[i] = ImagePairLoaderProcess(kwargs={'queue':self.queue,'loader':batch_loader})
            self.processes[i].daemon = True
            self.processes[i].start()

	top[0].reshape(self.batch_size, 3, params['cur_shape'][0],params['cur_shape'][1])
        top[1].reshape(self.batch_size, 3, params['cur_shape'][0], params['cur_shape'][1])
        top[2].reshape(self.batch_size, 3, params['next_shape'][0], params['next_shape'][1])
        top[3].reshape(self.batch_size, 1, params['next_shape'][0], params['next_shape'][1])
    
	if params['inverse_flow']:
	    assert params['cur_shape'] == params['next_shape']
	    top[4].reshape(self.batch_size, 2, params['next_shape'][0], params['next_shape'][1])
	    self.top_names.append('inverse_flow')
Beispiel #3
0
    def setup(self, bottom, top):
        params = eval(self.param_str)
        check_params(params,  
                nn_root=None,
                nn_shape=None,
                nn_query_size=1,
                nn_num=1,
                nn_db_size=np.inf,
                nn_ignore=1)
	
	self.params = Map(params)
	self.nn_db = DartDB(self.params.nn_root)
	self.nn = NN(self.nn_db, self.params.nn_db_size, self.params.nn_ignore)
	assert self.params.nn_num <= self.params.nn_query_size
Beispiel #4
0
    def setup(self, bottom, top):
        params = eval(self.param_str)
        check_params(params, port=None)
        self.port = params['port']

        self.context = zmq.Context.instance()
        self.sock = self.context.socket(zmq.REQ)
        self.sock.bind('tcp://*:' + self.port)
        cprint('client set up', bcolors.OKBLUE)
        #self.sock.send_pyobj(np.zeros((256,256)) )
        #self.sock.recv()
        #print bcolors.OKGREEN + 'dummy message sent'+bcolors.ENDC
        if len(top) > 0:
            top[0].reshape(1)
Beispiel #5
0
def del_user():
    form_data = flask_req.form if len(flask_req.form) != 0 else json.loads(
        flask_req.data)

    if not util.check_params(form_data, ('sid', 'pw')):
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.PARAMS_ERROR,
                'msg': '参数错误。'
            }), 400)

    sid = form_data.get('sid')
    pw = form_data.get('pw')

    count = user_col.delete_one({'sid': sid, 'pw': pw}).deleted_count

    if count:
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.SUCCESS,
                'msg': ''
            }))
    else:
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.FAILED,
                'msg': '未知错误,可能数据库正忙。'
            }))
Beispiel #6
0
def login():
    form_data = flask_req.form if len(flask_req.form) != 0 else json.loads(
        flask_req.data)

    if not util.check_params(form_data, ('sid', 'pw')):
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.PARAMS_ERROR,
                'msg': '参数错误。'
            }), 400)

    sid = form_data.get('sid')
    pw = form_data.get('pw')

    if user_col.find_one({'sid': sid, 'pw': pw}):
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.SUCCESS,
                'msg': '登录成功。'
            }))
    else:
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.FAILED,
                'msg': '学号或密码错误,请核对后重试!'
            }), 403)
Beispiel #7
0
def update_user_info():
    form_data = flask_req.form if len(flask_req.form) != 0 else json.loads(
        flask_req.data)

    if not util.check_params(form_data, ('sid', 'pw', 'new_user_info')):
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.PARAMS_ERROR,
                'msg': '参数错误。'
            }), 400)

    sid = form_data.get('sid')
    pw = form_data.get('pw')
    new_user_info = form_data.get('new_user_info')

    if not util.check_params(new_user_info, ('pw', 'coords', 'is_pause'),
                             method='have_one'):
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.PARAMS_ERROR,
                'msg': '参数错误。'
            }), 400)

    if new_user_info.get('pw'):
        new_user_info['is_pw_wrong'] = False

    count = user_col.update_one({
        'sid': sid,
        'pw': pw,
    }, {
        '$set': new_user_info
    }).matched_count

    if count:
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.SUCCESS,
                'msg': ''
            }))
    else:
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.FAILED,
                'msg': '未知错误,可能数据库正忙。'
            }))
Beispiel #8
0
def check_captcha():
    if not util.check_params(flask_req.args, ('v', 'cid')):
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.PARAMS_ERROR,
                'msg': '参数错误。'
            }), 400)

    client_captcha = flask_req.args.get('v')
    captcha_id = flask_req.args.get('cid')

    if client_captcha.lower() != captcha_dict.get(captcha_id):
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.FAILED,
                'msg': '验证码错误。'
            }))

    captcha_dict.pop(captcha_id)
    return jsonify({'code': const_.DEFAULT_CODE.SUCCESS, 'msg': ''})
Beispiel #9
0
def get_user_info():
    global users_queue_dict
    form_data = flask_req.form if len(flask_req.form) != 0 else json.loads(
        flask_req.data)

    if not util.check_params(form_data, ('sid', 'pw')):
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.PARAMS_ERROR,
                'msg': '参数错误。'
            }), 400)

    sid = form_data.get('sid')
    pw = form_data.get('pw')

    specific_user = user_col.find_one({
        'sid': sid,
        'pw': pw
    }, {
        '_id': False,
        'sid': False,
        'pw': False,
        'coords': False
    })

    if specific_user:
        specific_user = util.bson_to_obj(specific_user)
        with queue_lock.r_locked():
            in_queue = users_queue_dict.get(sid, [0, -1])
        specific_user['in_queue'] = in_queue[1]
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.SUCCESS,
                'user_info': specific_user,
            }))
    else:
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.FAILED,
                'user_info': None,
            }), 404)
Beispiel #10
0
    def setup(self, bottom, top):
        params = eval(self.param_str)
        check_params(params, 
                batch_size=1, 
                db_root=None, 
                nn_root='',
                subtract_mean=False,
                shuffle=True,
                num_threads = 1, 
                im_shape=[128, 128],
                nn_shape='',
                load_nn=False,
                nn_query_size=1,
                hist_eq=False,
                nn_db_size=np.inf)
	
	#im_shape and nn_shape should be list of image sizes [(128, 128), (256, 256)]
	if not hasattr(params['im_shape'][0], '__len__'):
	    params['im_shape'] = [params['im_shape']]
	    
	if params['nn_shape'] == '':
	    params['nn_shape'] = params['im_shape']
	
	if not hasattr(params['nn_shape'][0], '__len__'):
	    params['nn_shape'] = [params['nn_shape']]
	    
	self.load_nn = params['load_nn']
        self.batch_size = params['batch_size']
        self.num_threads = params['num_threads']
        self.queue = Queue(self.batch_size)
        self.processes = [None]*self.num_threads
	nn_db = None
        db = DartDB(params['db_root'])
        
	#Reshape tops
	cur_top = 0
	self.top_names = []
	for im_shape in params['im_shape']:
	    self.top_names.extend(['img_' + shape_str(im_shape), 'seg_' + shape_str(im_shape)])
	    top[cur_top].reshape(self.batch_size, 3, im_shape[0], im_shape[1])
	    top[cur_top + 1].reshape(self.batch_size, 1, im_shape[0], im_shape[1])
	    cur_top += 2
	self.top_names.append('jp')
        top[cur_top].reshape(self.batch_size, db.jps.shape[1])
        cur_top += 1
        if self.load_nn:
	    for nn_shape in params['nn_shape']:
		self.top_names.extend(['nn_img_' + shape_str(nn_shape), 'nn_seg_' + shape_str(nn_shape)])
		top[cur_top].reshape(self.batch_size, 3, nn_shape[0], nn_shape[1])
		top[cur_top + 1].reshape(self.batch_size, 1, nn_shape[0], nn_shape[1])
		cur_top += 2
	    self.top_names.append('nn_jp')
	    top[cur_top].reshape(self.batch_size, db.jps.shape[1])
	    cur_top += 1
	    if params['nn_root'] == '':
		params['nn_root'] = params['db_root']
		nn_db = db
	    else:
		nn_db = DartDB(params['nn_root'])
	#Initiate and start processes
        for i in range(self.num_threads):
            data_loader = DataLoader(params, db, nn_db)
            self.processes[i] = DataLoaderProcess(kwargs={'queue':self.queue,'loader':data_loader})
            self.processes[i].daemon = True
            self.processes[i].start()
Beispiel #11
0
 def setup(self, bottom, top):
     params = eval(self.param_str)
     check_params(params, scale=1.0)
     self.scale = params['scale']
Beispiel #12
0
    def setup(self, bottom, top):
	params = eval(self.param_str)
	check_params(params, n_segs=400, compactness=30)
	self.n_segs = params['n_segs']
        self.compactness = params['compactness']
    def setup(self, bottom, top):
	params = eval(self.param_str)
	check_params(params, scale=1.0)
	self.scale = params['scale']
Beispiel #14
0
def signup():
    form_data = flask_req.form if len(flask_req.form) != 0 else json.loads(
        flask_req.data)

    if not util.check_params(form_data, ('code', 'sid', 'pw')):
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.PARAMS_ERROR,
                'valid': const_.SIGNUP_CHECK.UNKNOWN,
                'msg': '参数错误。'
            }), 403)

    client_code = form_data.get('code')
    sid = form_data.get('sid')
    pw = form_data.get('pw')

    if user_col.count_documents({'sid': sid}) != 0:
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.FAILED,
                'valid': const_.SIGNUP_CHECK.UNKNOWN,
                'msg': '请勿重复注册。'
            }), 403)

    server_code = invitation_col.find_one({'code': client_code},
                                          {'times': True})

    if not server_code:
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.SUCCESS,
                'valid': const_.SIGNUP_CHECK.INVALID,
                'msg': '邀请码无效。'
            }))
    elif server_code['times'] == 0:
        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.SUCCESS,
                'valid': const_.SIGNUP_CHECK.OUTDATED,
                'msg': '邀请码已过期。'
            }))
    else:
        times = server_code['times'] - 1 \
            if server_code['times'] > 0 \
            else server_code['times']

        coords = form_data.get('coords') if form_data.get('coords') else {
            'latitude': FAKE_LAT,
            'longitude': FAKE_LONG
        }

        now_hour = localtime(time()).tm_hour
        now_minute = localtime(time()).tm_min

        new_user = {
            'sid': sid,
            'pw': pw,
            'coords': coords,
            'is_pause': False,
            'is_pw_wrong': False,
            'is_up': {
                'morning':
                const_.UP_STATUS.UNKNOWN if now_hour > 12 or
                (now_hour == 11 and now_minute > 45) else
                const_.UP_STATUS.NOT_UP,
                'afternoon':
                const_.UP_STATUS.UNKNOWN if now_hour > 18 or
                (now_hour == 17 and now_minute > 45) else
                const_.UP_STATUS.NOT_UP,
                'evening':
                const_.UP_STATUS.UNKNOWN if now_hour > 22 or
                (now_hour == 21 and now_minute > 45) else
                const_.UP_STATUS.NOT_UP
            }
        }

        user_col.insert_one(new_user)
        invitation_col.update_one({'code': client_code},
                                  {'$set': {
                                      'times': times
                                  }})

        return make_response(
            jsonify({
                'code': const_.DEFAULT_CODE.SUCCESS,
                'valid': const_.SIGNUP_CHECK.NORMAL,
                'msg': ''
            }))
    def setup(self, bottom, top):
        self.top_names = [
            'current_image', 'fg_image', 'bg_image', 'next_image',
            'current_mask', 'label'
        ]
        self.flow_names = []
        params = eval(self.param_str)
        check_params(params,
                     result_dir='',
                     batch_size=1,
                     split=None,
                     port=None,
                     im_shape=0,
                     shuffle=False,
                     max_len=0,
                     bgr=False,
                     scale_256=False,
                     bb1_enlargment=2.2,
                     bb2_enlargment=2.2,
                     cur_shape=0,
                     next_shape=0,
                     mask_mean=.5,
                     mean=None,
                     flow_params=[],
                     flow_method='None',
                     mask_threshold=0.5,
                     augmentations=[])

        #For backward compatibility
        if params['next_shape'] == 0 or params['cur_shape'] == 0:
            if params['im_shape'] == 0:
                raise Exception
            params['next_shape'] = params['im_shape']
            params['cur_shape'] = [
                params['im_shape'][0] / 2, params['im_shape'][1] / 2
            ]

        if params['split'] == 'training':
            db_sets = [
                'training', 'test_pascal', 'training_pascal',
                'training_segtrackv2', 'training_jumpcut'
            ]
        elif params['split'] == 'test':
            db_sets = ['test']
        params['db_sets'] = db_sets

        self.batch_size = params['batch_size']
        self.queue = Queue(self.batch_size)
        self.process = SequenceLoaderProcess(
            kwargs={
                'queue': self.queue,
                'loader': SequenceLoader(params),
                'batch_size': self.batch_size,
                'port': params['port'],
                'result_dir': params['result_dir']
            })
        self.process.daemon = True
        self.process.start()

        top[0].reshape(self.batch_size, 3, params['cur_shape'][0],
                       params['cur_shape'][1])
        top[1].reshape(self.batch_size, 3, params['cur_shape'][0],
                       params['cur_shape'][1])
        top[2].reshape(self.batch_size, 3, params['cur_shape'][0],
                       params['cur_shape'][1])
        top[3].reshape(self.batch_size, 3, params['next_shape'][0],
                       params['next_shape'][1])
        top[4].reshape(self.batch_size, 1, params['cur_shape'][0],
                       params['cur_shape'][1])
        top[5].reshape(self.batch_size, 1, params['next_shape'][0],
                       params['next_shape'][1])

        for i in range(len(params['flow_params'])):
            ##in out network we have flow_coordinate = down_scale * 'name'_coordinate + offset
            ##in python resize we have flow_coordinate = down_scale * 'name'_coordinate + (down_scale - 1)/2 - pad
            ## ==> (down_scale - 1)/2 - pad = offset ==> pad = -offset + (down_scale - 1)/2

            name, down_scale, offset, flow_scale = params['flow_params'][i]
            pad = -offset + (down_scale - 1) / 2
            assert pad == int(pad) and pad >= 0 and offset <= 0
            h = int(
                np.floor(
                    float(params['next_shape'][0] + 2 * pad) / down_scale))
            w = int(
                np.floor(
                    float(params['next_shape'][1] + 2 * pad) / down_scale))
            top[i + 6].reshape(self.batch_size, 2, h, w)
            self.top_names.append(name)
            self.flow_names.append(name)