print(args) # ================ init if args.cfg_file is None: print 'Please the config file for training! (--cfg)' sys.exit() # load trainging config file train_cfg = parse_cfg_file(args.cfg_file) print('Using config:') pprint.pprint(train_cfg) # set conf if train_cfg.common.rpn_cfg: rpn_config.cfg_from_file(train_cfg.common.rpn_cfg) print('RPN using config:') pprint.pprint(rpn_config.cfg) if train_cfg.common.fast_rcnn_cfg: fast_rcnn_config.cfg_from_file(train_cfg.common.fast_rcnn_cfg) print('Fast-RCNN using config:') pprint.pprint(fast_rcnn_config.cfg) # set up caffe if not args.randomize: # fix the random seeds (numpy and caffe) for reproducibility np.random.seed(rpn_config.cfg.RNG_SEED) caffe.set_random_seed(rpn_config.cfg.RNG_SEED) if args.cpu_mode: caffe.set_mode_cpu()
args = parser.parse_args() return args if __name__ == '__main__': args = parse_args() prototxt = args.prototxt caffemodel = args.caffemodel anchors = args.anchors print('Called with args:') print(args) if args.cfg_file is not None: cfg_from_file(args.cfg_file) print('Using config:') pprint.pprint(cfg) while not os.path.exists(caffemodel) and args.wait: print('Waiting for {} to exist...'.format(caffemodel)) time.sleep(10) if args.cpu_mode: caffe.set_mode_cpu() else: caffe.set_mode_gpu() caffe.set_device(args.gpu_id) net = caffe.Net(prototxt, caffemodel, caffe.TEST)
def predict(self): #args = parse_args() prototxt = self.defining caffemodel = self.net anchors = self.anchors #print('Called with args:') #print(args) cfg_from_file(self.cfg) print('Using config:') pprint.pprint(cfg) while not os.path.exists(caffemodel): print('Waiting for {} to exist...'.format(caffemodel)) time.sleep(10) caffe.set_mode_gpu() caffe.set_device(0) net = caffe.Net(prototxt, caffemodel, caffe.TEST) net.name = os.path.splitext(os.path.basename(caffemodel))[0] print '\n\nLoaded network {:s}'.format(caffemodel) #img_list = ['tr.jpg'] #for img_name in img_list: # print '~' * 20 # im_file = os.path.join(cfg.ROOT_DIR, 'data', 'demo', img_name) # print 'Demo for image: `{:s}`'.format(im_file) # demo(net, im_file, anchors) # plt.show() db = MongoClient('10.76.0.143', 27017)['plate'] db.authenticate('plateReader', 'IamReader') total_num = db.image.count() # total_num=1407 #bad=open('bad_list.txt','r') bad = open('id_path.txt', 'r') #bad=open('id_path.txt','r') #print total_num #idlist=range(total_num) #print idlist error1 = 0 f = open('re_predict_result_new.txt', 'w') for idlist in bad: #for i in bad: # num=int(i)-1 #print count #print num #print type(num) re_num = re.split(' ', idlist) #print re_num[0] num = int(re_num[0]) #print num temp = db.image.find_one({'_id': int(num)}) #temp=db.image.find_one({'_id',num+1}) if temp: #temp=db.image.find_one({'_id':num+1}) im_file = temp['path'] img = exif.load_exif_jpg(im_file) width = 1280 height = 720 multi = img.shape[0] * img.shape[1] * 1.0 / (width * height) multi = math.sqrt(multi) print multi resized_img = cv2.resize( img, (int(img.shape[1] / multi), int(img.shape[0] / multi))) resized_img_name = os.path.join('plate_buffer', 'resized_img.jpg') cv2.imwrite(resized_img_name, resized_img) re_img = cv2.imread(resized_img_name) #e_img_size = re_img.shape print im_file try: presicion = demo(net, resized_img_name, anchors) print presicion #print 'result' #print presicion #print int(presicion[0][2:3]) #print "a" #print len(temp['points']) #print "b" if len(temp['points']) > 0: f.write(str(num) + ' ') #f.write(str(temp['points'][0][0][0:1][0])+' '+str(temp['points'][0][0][1:2][0])+' ') #f.write(str(temp['points'][0][1][0:1][0])+' '+str(temp['points'][0][1][1:2][0])+' ') #f.write(str(temp['points'][0][2][0:1][0])+' '+str(temp['points'][0][2][1:2][0])+' ') #f.write(str(temp['points'][0][3][0:1][0])+' '+str(temp['points'][0][3][1:2][0])+' ') #print 'flag1' if len(presicion) != 0: f.write('*' + ' ') f.write( str(int(presicion[0][2:3] * multi + 1)) + ' ' + str(int(presicion[0][1:2] * multi - 1)) + ' ') f.write( str(int(presicion[0][2:3] * multi + 1)) + ' ' + str(int(presicion[0][3:4] * multi + 1)) + ' ') f.write( str(int(presicion[0][0:1] * multi - 1)) + ' ' + str(int(presicion[0][3:4] * multi + 1)) + ' ') f.write( str(int(presicion[0][0:1] * multi - 1)) + ' ' + str(int(presicion[0][1:2] * multi - 1))) #error1=error1+1 else: f.write('* ' + '0 ' + '0 ' + '0 ' + '0 ' + '0 ' + '0 ' + '0 ' + '0') f.write('\n') # print 'flags2' except: print 'we are wrong' pass #break f.close()
parser.print_help() sys.exit(1) args = parser.parse_args() return args if __name__ == '__main__': args = parse_args() print('Called with args:') print(args) # ================ init # set conf if args.cfg_file is not None: rpn_config.cfg_from_file(args.cfg_file) print('RPN using config:') pprint.pprint(rpn_config.cfg) # set up caffe if not args.randomize: # fix the random seeds (numpy and caffe) for reproducibility np.random.seed(rpn_config.cfg.RNG_SEED) caffe.set_random_seed(rpn_config.cfg.RNG_SEED) if args.cpu_mode: caffe.set_mode_cpu() else: caffe.set_mode_gpu() caffe.set_device(args.gpu_id)
sys.exit(1) args = parser.parse_args() return args if __name__ == '__main__': args = parse_args() print('Called with args:') print(args) # ================ init # set conf if args.cfg_file is not None: rpn_config.cfg_from_file(args.cfg_file) print('RPN using config:') pprint.pprint(rpn_config.cfg) # set up caffe if not args.randomize: # fix the random seeds (numpy and caffe) for reproducibility np.random.seed(rpn_config.cfg.RNG_SEED) caffe.set_random_seed(rpn_config.cfg.RNG_SEED) if args.cpu_mode: caffe.set_mode_cpu() else: caffe.set_mode_gpu() caffe.set_device(args.gpu_id)
def predict(self): #args = parse_args() prototxt = self.defining caffemodel = self.net anchors = self.anchors #print('Called with args:') #print(args) cfg_from_file(self.cfg) print('Using config:') pprint.pprint(cfg) while not os.path.exists(caffemodel): print('Waiting for {} to exist...'.format(caffemodel)) time.sleep(10) caffe.set_mode_gpu() caffe.set_device(0) net = caffe.Net(prototxt, caffemodel, caffe.TEST) net.name = os.path.splitext(os.path.basename(caffemodel))[0] print '\n\nLoaded network {:s}'.format(caffemodel) #img_list = ['tr.jpg'] #for img_name in img_list: # print '~' * 20 # im_file = os.path.join(cfg.ROOT_DIR, 'data', 'demo', img_name) # print 'Demo for image: `{:s}`'.format(im_file) # demo(net, im_file, anchors) # plt.show() db = MongoClient('10.76.0.143', 27017)['plate'] db.authenticate('plateReader', 'IamReader') total_num=db.image.count() # total_num=1407 #bad=open('bad_list.txt','r') bad=open('id_path.txt','r') #bad=open('id_path.txt','r') #print total_num #idlist=range(total_num) #print idlist error1=0 f=open('re_predict_result_new.txt','w') for idlist in bad: #for i in bad: # num=int(i)-1 #print count #print num #print type(num) re_num=re.split(' ',idlist) #print re_num[0] num=int(re_num[0]) #print num temp=db.image.find_one({'_id':int(num)}) #temp=db.image.find_one({'_id',num+1}) if temp: #temp=db.image.find_one({'_id':num+1}) im_file=temp['path'] img = exif.load_exif_jpg(im_file) width = 1280 height = 720 multi = img.shape[0]*img.shape[1]*1.0/(width*height) multi = math.sqrt(multi) print multi resized_img = cv2.resize(img,(int(img.shape[1]/multi), int(img.shape[0]/multi))) resized_img_name = os.path.join('plate_buffer', 'resized_img.jpg') cv2.imwrite(resized_img_name, resized_img) re_img = cv2.imread(resized_img_name) #e_img_size = re_img.shape print im_file try: presicion= demo(net,resized_img_name,anchors) print presicion #print 'result' #print presicion #print int(presicion[0][2:3]) #print "a" #print len(temp['points']) #print "b" if len(temp['points'])>0: f.write(str(num)+' ') #f.write(str(temp['points'][0][0][0:1][0])+' '+str(temp['points'][0][0][1:2][0])+' ') #f.write(str(temp['points'][0][1][0:1][0])+' '+str(temp['points'][0][1][1:2][0])+' ') #f.write(str(temp['points'][0][2][0:1][0])+' '+str(temp['points'][0][2][1:2][0])+' ') #f.write(str(temp['points'][0][3][0:1][0])+' '+str(temp['points'][0][3][1:2][0])+' ') #print 'flag1' if len(presicion)!=0: f.write('*'+' ') f.write(str(int(presicion[0][2:3]*multi+1))+' '+str(int(presicion[0][1:2]*multi-1))+' ') f.write(str(int(presicion[0][2:3]*multi+1))+' '+str(int(presicion[0][3:4]*multi+1))+' ') f.write(str(int(presicion[0][0:1]*multi-1))+' '+str(int(presicion[0][3:4]*multi+1))+' ') f.write(str(int(presicion[0][0:1]*multi-1))+' '+str(int(presicion[0][1:2]*multi-1))) #error1=error1+1 else: f.write('* '+'0 '+'0 '+'0 '+'0 '+'0 '+'0 '+'0 '+'0') f.write('\n') # print 'flags2' except: print 'we are wrong' pass #break f.close()
def predict(self): #args = parse_args() prototxt = self.defining caffemodel = self.net anchors = self.anchors #print('Called with args:') #print(args) cfg_from_file(self.cfg) print('Using config:') pprint.pprint(cfg) while not os.path.exists(caffemodel): print('Waiting for {} to exist...'.format(caffemodel)) time.sleep(10) caffe.set_mode_gpu() caffe.set_device(0) net = caffe.Net(prototxt, caffemodel, caffe.TEST) net.name = os.path.splitext(os.path.basename(caffemodel))[0] print '\n\nLoaded network {:s}'.format(caffemodel) #img_list = ['tr.jpg'] #for img_name in img_list: # print '~' * 20 # im_file = os.path.join(cfg.ROOT_DIR, 'data', 'demo', img_name) # print 'Demo for image: `{:s}`'.format(im_file) # demo(net, im_file, anchors) # plt.show() db = MongoClient('10.76.0.143', 27017)['plate'] db.authenticate('plateReader', 'IamReader') total_num=db.image.count() total_num=103470 #bad=open('bad_list.txt','r') #idlist=range(total_num) #print idlist error1=0 f=open('predict_result1.txt','w') for num in range(total_num): #for i in bad: # num=int(i)-1 #print count temp=db.image.find_one({'_id':num+1}) #temp=db.image.find_one({'_id',num+1}) if temp: #temp=db.image.find_one({'_id':num+1}) im_file=temp['path'] print im_file try: presicion= demo(net,im_file,anchors) print presicion #print 'result' #print presicion #print int(presicion[0][2:3]) #print temp['points'] if len(temp['points'])>0: f.write(str(num+1)+' ') f.write(str(temp['points'][0][0][0:1][0])+' '+str(temp['points'][0][0][1:2][0])+' ') f.write(str(temp['points'][0][1][0:1][0])+' '+str(temp['points'][0][1][1:2][0])+' ') f.write(str(temp['points'][0][2][0:1][0])+' '+str(temp['points'][0][2][1:2][0])+' ') f.write(str(temp['points'][0][3][0:1][0])+' '+str(temp['points'][0][3][1:2][0])+' ') if len(presicion)!=0: f.write('*'+' ') f.write(str(int(presicion[0][2:3]))+' '+str(int(presicion[0][1:2]))+' ') f.write(str(int(presicion[0][2:3]))+' '+str(int(presicion[0][3:4]))+' ') f.write(str(int(presicion[0][0:1]))+' '+str(int(presicion[0][3:4]))+' ') f.write(str(int(presicion[0][0:1]))+' '+str(int(presicion[0][1:2]))) #error1=error1+1 else: f.write('* '+'0 '+'0 '+'0 '+'0 '+'0 '+'0 '+'0 '+'0') f.write('\n') except: print 'we are wrong' pass
sys.exit(1) args = parser.parse_args() return args if __name__ == '__main__': args = parse_args() prototxt = args.prototxt caffemodel = args.caffemodel anchors = args.anchors print('Called with args:') print(args) if args.cfg_file is not None: cfg_from_file(args.cfg_file) print('Using config:') pprint.pprint(cfg) while not os.path.exists(caffemodel): print('Waiting for {} to exist...'.format(caffemodel)) time.sleep(10) if args.cpu_mode: caffe.set_mode_cpu() else: caffe.set_mode_gpu() caffe.set_device(args.gpu_id) net = caffe.Net(prototxt, caffemodel, caffe.TEST)