def deblur1(path): args = { 'model': 'color', 'datalist': 'C:/Users/smita/Desktop/face-group-recognition-facerecognition-api-updated/datalist_gopro.txt', 'batch_size': 16, 'epoch': 4000, 'lr': 1e-4, 'gpu': '0', 'phase': 'test' } print(args['model']) # args = parse_args() # set gpu/cpu mode # if int(args.gpu_id) >= 0: # os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu_id # else: os.environ['CUDA_VISIBLE_DEVICES'] = '' # set up deblur models deblur = model.DEBLUR(args) if args['phase'] == 'test': out = "hello.png" res = deblur.test(720, 1280, path, out) path = 'static/Quality/' + str(time.time()) + ".png" cv2.imwrite(path, res) # print(x) return path elif args['phase'] == 'train': deblur.train() else: print('phase should be set to either test or train')
def main(_): args = parse_args() # set gpu/cpu mode if int(args.gpu_id) >= 0: os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu_id device = '/gpu:{}'.format(args.gpu_id) else: os.environ['CUDA_VISIBLE_DEVICES'] = '' device = '/cpu:0' config = tf.ConfigProto(allow_soft_placement=True) config.gpu_options.allow_growth = True # set up deblur models with tf.device(device): with tf.Session(config=config) as sess: deblur = model.DEBLUR(args) if args.phase == 'test': deblur.test(sess, args.height, args.width, args.input_path, args.output_path) elif args.phase == 'train': deblur.train(sess) else: print('phase should be set to either test or train')
def main(_): args = parse_args() os.environ['TF_ENABLE_AUTO_MIXED_PRECISION'] = '1' os.environ['TF_CPP_VMODULE'] = "auto_mixed_precision=2" # set gpu/cpu mode if int(args.gpu_id) >= 0: os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu_id else: os.environ['CUDA_VISIBLE_DEVICES'] = '' # set up deblur models deblur = model.DEBLUR(args) if args.phase == 'test': deblur.test(args.height, args.width, args.input_path, args.output_path) elif args.phase == 'train': deblur.train() elif args.phase == 'check': deblur.check(args.height, args.width) elif args.phase == 'convert': deblur.convert_tflite(args.height, args.width) elif args.phase == 'eval': deblur.eval(file_dir=args.eval_path) else: print('phase should be set to either test or train')
def main(_): args = parse_args() # set gpu/cpu mode if int(args.gpu_id) >= 0: os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu_id else: os.environ['CUDA_VISIBLE_DEVICES'] = '' # set up deblur models M = model.DEBLUR(args) if not os.path.exists(args.output_path): os.makedirs(args.output_path) with tf.Graph().as_default(): before = tf.placeholder(tf.float32, shape=[1, args.height, args.width, 3]) current = tf.placeholder(tf.float32, shape=[1, args.height, args.width, 3]) after = tf.placeholder(tf.float32, shape=[1, args.height, args.width, 3]) predict = M.generator(before, current, after, istrain=False) saver = tf.train.Saver() with tf.Session() as sess: checkpoint_dir = os.path.join('./checkpoints/', args.name) load_checkpoint(sess, checkpoint_dir, saver) imgsName = sorted(os.listdir(args.input_path)) time_start = time.time() for imgName in imgsName: print('Processing: %s' % imgName) img = cv2.imread(os.path.join(args.input_path, imgName)) inputs = split_input(img) inputs = [np.expand_dims(img, 0) for img in inputs] result = sess.run(predict, feed_dict={ before: inputs[0], current: inputs[1], after: inputs[2] }) result = result[1][0, :, :, :] result = im2uint8(result) cv2.imwrite(os.path.join(args.output_path, imgName), result) time_end = time.time() process_time = (time_end - time_start) print('avage process time = %.4f' % (process_time / len(imgsName)))
def main(_): args = parse_args() # set gpu/cpu mode if int(args.gpu_id) >= 0: os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu_id else: os.environ['CUDA_VISIBLE_DEVICES'] = '' # set up deblur models deblur = model.DEBLUR(args) if args.phase == 'test': deblur.test(args.height, args.width, args.input_path, args.output_path) elif args.phase == 'train': deblur.train() else: print('phase should be set to either test or train')
def main(_): args = parse_args() # Set gpu/cpu mode. if int(args.gpu_id) >= 0: os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu_id else: os.environ['CUDA_VISIBLE_DEVICES'] = '-1' # Set up deblur models. deblur = model.DEBLUR(args) if args.phase == 'test': deblur.validate() elif args.phase == 'train': deblur.train() else: print('Runtime error: args.phase can be only [train, test]') exit(1)
def main(_): args = parse_args() # set gpu/cpu mode if int(args.gpu_id) >= 0: os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu_id else: os.environ['CUDA_VISIBLE_DEVICES'] = '' checkpoint_dir = os.path.join('./checkpoints/', args.name) logger.set_logger_dir(checkpoint_dir) # set up deblur models M = model.DEBLUR(args) ds_train = get_data(args.dataroot, phase='train', crop_size=args.cropSize, batch_size=args.batchSize) ds_val = get_data(args.dataroot, phase='val', crop_size=args.cropSize, batch_size=args.batchSize) trainer = SeparateGANTrainer(ds_train, M, g_period=6) trainer.train_with_defaults( callbacks=[ ModelSaver(max_to_keep=5, checkpoint_dir=checkpoint_dir), ScheduledHyperParamSetter('learning_rate', [(300, args.learning_rate), (args.max_epoch, 0)], interp='linear'), InferenceRunner(ds_val, [ ScalarStats('PSNR_BASE'), ScalarStats('PSNR_2'), ScalarStats('PSNR_IMPRO2'), ScalarStats('pixel_loss2'), ScalarStats('feature_loss2') ]) ], session_init=SaverRestore(checkpoint_dir + '/model-431249.data-00000-of-00001') if args.continue_train else None, starting_epoch=1, steps_per_epoch=args.steps_per_epoch, max_epoch=args.max_epoch)
def main(_): args = parse_args() deblur = model.DEBLUR(args) deblur.test_one(args.height, args.width, args.input_path, args.output_path)
global deblur global train_dir global graph global sess global ALLOWED_EXTENSIONS ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg']) upload_directory = '/src/upload/' create_directory(upload_directory) checkpoint_dir = "/src/checkpoints/" create_directory(checkpoint_dir) url_prefix = 'http://pretrained-models.auth-18b62333a540498882ff446ab602528b.storage.gra.cloud.ovh.net/image/SRN-Deblur/' model_zip = "srndeblur_models.zip" get_model_bin(url_prefix + model_zip, checkpoint_dir + model_zip) os.system("cd " + checkpoint_dir + " && unzip " + model_zip) checkpoint_dir = os.path.join(checkpoint_dir, args.model) deblur = model.DEBLUR(args) port = 5000 host = '0.0.0.0' app.run(host=host, port=port, threaded=True)