benchmark.lua 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. require 'pl'
  2. local __FILE__ = (function() return string.gsub(debug.getinfo(2, 'S').source, "^@", "") end)()
  3. package.path = path.join(path.dirname(__FILE__), "..", "lib", "?.lua;") .. package.path
  4. require 'xlua'
  5. require 'w2nn'
  6. local iproc = require 'iproc'
  7. local reconstruct = require 'reconstruct'
  8. local image_loader = require 'image_loader'
  9. local gm = require 'graphicsmagick'
  10. local cjson = require 'cjson'
  11. local cmd = torch.CmdLine()
  12. cmd:text()
  13. cmd:text("waifu2x-benchmark")
  14. cmd:text("Options:")
  15. cmd:option("-dir", "./data/test", 'test image directory')
  16. cmd:option("-model1_dir", "./models/anime_style_art_rgb", 'model1 directory')
  17. cmd:option("-model2_dir", "", 'model2 directory (optional)')
  18. cmd:option("-method", "scale", '(scale|noise|noise_scale|user)')
  19. cmd:option("-filter", "Catrom", "downscaling filter (Box|Lanczos|Catrom(Bicubic))")
  20. cmd:option("-resize_blur", 1.0, 'blur parameter for resize')
  21. cmd:option("-color", "y", '(rgb|y)')
  22. cmd:option("-noise_level", 1, 'model noise level')
  23. cmd:option("-jpeg_quality", 75, 'jpeg quality')
  24. cmd:option("-jpeg_times", 1, 'jpeg compression times')
  25. cmd:option("-jpeg_quality_down", 5, 'value of jpeg quality to decrease each times')
  26. cmd:option("-range_bug", 0, 'Reproducing the dynamic range bug that is caused by MATLAB\'s rgb2ycbcr(1|0)')
  27. cmd:option("-save_image", 0, 'save converted images')
  28. cmd:option("-save_baseline_image", 0, 'save baseline images')
  29. cmd:option("-output_dir", "./", 'output directroy')
  30. cmd:option("-show_progress", 1, 'show progressbar')
  31. cmd:option("-baseline_filter", "Catrom", 'baseline interpolation (Box|Lanczos|Catrom(Bicubic))')
  32. cmd:option("-save_info", 0, 'save score and parameters to benchmark.txt')
  33. cmd:option("-save_all", 0, 'group -save_info, -save_image and -save_baseline_image option')
  34. cmd:option("-thread", -1, 'number of CPU threads')
  35. cmd:option("-tta", 0, 'use tta')
  36. cmd:option("-tta_level", 8, 'tta level')
  37. cmd:option("-crop_size", 128, 'patch size per process')
  38. cmd:option("-batch_size", 1, 'batch_size')
  39. cmd:option("-force_cudnn", 0, 'use cuDNN backend')
  40. cmd:option("-yuv420", 0, 'use yuv420 jpeg')
  41. cmd:option("-name", "", 'model name for user method')
  42. cmd:option("-x_dir", "", 'input image for user method')
  43. cmd:option("-y_dir", "", 'groundtruth image for user method. filename must be the same as x_dir')
  44. local function to_bool(settings, name)
  45. if settings[name] == 1 then
  46. settings[name] = true
  47. else
  48. settings[name] = false
  49. end
  50. end
  51. local opt = cmd:parse(arg)
  52. torch.setdefaulttensortype('torch.FloatTensor')
  53. if cudnn then
  54. cudnn.fastest = true
  55. cudnn.benchmark = true
  56. end
  57. to_bool(opt, "force_cudnn")
  58. to_bool(opt, "yuv420")
  59. to_bool(opt, "save_all")
  60. to_bool(opt, "tta")
  61. if opt.save_all then
  62. opt.save_image = true
  63. opt.save_info = true
  64. opt.save_baseline_image = true
  65. else
  66. to_bool(opt, "save_image")
  67. to_bool(opt, "save_info")
  68. to_bool(opt, "save_baseline_image")
  69. end
  70. to_bool(opt, "show_progress")
  71. if opt.thread > 0 then
  72. torch.setnumthreads(tonumber(opt.thread))
  73. end
  74. local function rgb2y_matlab(x)
  75. local y = torch.Tensor(1, x:size(2), x:size(3)):zero()
  76. x = iproc.byte2float(x)
  77. y:add(x[1] * 65.481)
  78. y:add(x[2] * 128.553)
  79. y:add(x[3] * 24.966)
  80. y:add(16.0)
  81. return y:byte():float()
  82. end
  83. local function RGBMSE(x1, x2)
  84. x1 = iproc.float2byte(x1):float()
  85. x2 = iproc.float2byte(x2):float()
  86. return (x1 - x2):pow(2):mean()
  87. end
  88. local function YMSE(x1, x2)
  89. if opt.range_bug == 1 then
  90. local x1_2 = rgb2y_matlab(x1)
  91. local x2_2 = rgb2y_matlab(x2)
  92. return (x1_2 - x2_2):pow(2):mean()
  93. else
  94. local x1_2 = image.rgb2y(x1):mul(255.0)
  95. local x2_2 = image.rgb2y(x2):mul(255.0)
  96. return (x1_2 - x2_2):pow(2):mean()
  97. end
  98. end
  99. local function MSE(x1, x2, color)
  100. if color == "y" then
  101. return YMSE(x1, x2)
  102. else
  103. return RGBMSE(x1, x2)
  104. end
  105. end
  106. local function PSNR(x1, x2, color)
  107. local mse = math.max(MSE(x1, x2, color), 1)
  108. return 10 * math.log10((255.0 * 255.0) / mse)
  109. end
  110. local function MSE2PSNR(mse)
  111. return 10 * math.log10((255.0 * 255.0) / math.max(mse, 1))
  112. end
  113. local function transform_jpeg(x, opt)
  114. for i = 1, opt.jpeg_times do
  115. jpeg = gm.Image(x, "RGB", "DHW")
  116. jpeg:format("jpeg")
  117. if opt.yuv420 then
  118. jpeg:samplingFactors({2.0, 1.0, 1.0})
  119. else
  120. jpeg:samplingFactors({1.0, 1.0, 1.0})
  121. end
  122. blob, len = jpeg:toBlob(opt.jpeg_quality - (i - 1) * opt.jpeg_quality_down)
  123. jpeg:fromBlob(blob, len)
  124. x = jpeg:toTensor("byte", "RGB", "DHW")
  125. end
  126. return iproc.byte2float(x)
  127. end
  128. local function baseline_scale(x, filter)
  129. return iproc.scale(x,
  130. x:size(3) * 2.0,
  131. x:size(2) * 2.0,
  132. filter)
  133. end
  134. local function transform_scale(x, opt)
  135. return iproc.scale(x,
  136. x:size(3) * 0.5,
  137. x:size(2) * 0.5,
  138. opt.filter, opt.resize_blur)
  139. end
  140. local function transform_scale_jpeg(x, opt)
  141. x = iproc.scale(x,
  142. x:size(3) * 0.5,
  143. x:size(2) * 0.5,
  144. opt.filter, opt.resize_blur)
  145. for i = 1, opt.jpeg_times do
  146. jpeg = gm.Image(x, "RGB", "DHW")
  147. jpeg:format("jpeg")
  148. if opt.yuv420 then
  149. jpeg:samplingFactors({2.0, 1.0, 1.0})
  150. else
  151. jpeg:samplingFactors({1.0, 1.0, 1.0})
  152. end
  153. blob, len = jpeg:toBlob(opt.jpeg_quality - (i - 1) * opt.jpeg_quality_down)
  154. jpeg:fromBlob(blob, len)
  155. x = jpeg:toTensor("byte", "RGB", "DHW")
  156. end
  157. return iproc.byte2float(x)
  158. end
  159. local function benchmark(opt, x, model1, model2)
  160. local mse
  161. local model1_mse = 0
  162. local model2_mse = 0
  163. local baseline_mse = 0
  164. local model1_psnr = 0
  165. local model2_psnr = 0
  166. local baseline_psnr = 0
  167. local model1_time = 0
  168. local model2_time = 0
  169. local scale_f = reconstruct.scale
  170. local image_f = reconstruct.image
  171. if opt.tta then
  172. scale_f = function(model, scale, x, block_size, batch_size)
  173. return reconstruct.scale_tta(model, opt.tta_level,
  174. scale, x, block_size, batch_size)
  175. end
  176. image_f = function(model, x, block_size, batch_size)
  177. return reconstruct.image_tta(model, opt.tta_level,
  178. x, block_size, batch_size)
  179. end
  180. end
  181. for i = 1, #x do
  182. local basename = x[i].basename
  183. local input, model1_output, model2_output, baseline_output, ground_truth
  184. if opt.method == "scale" then
  185. input = transform_scale(x[i].y, opt)
  186. ground_truth = x[i].y
  187. if opt.force_cudnn and i == 1 then -- run cuDNN benchmark first
  188. model1_output = scale_f(model1, 2.0, input, opt.crop_size, opt.batch_size)
  189. if model2 then
  190. model2_output = scale_f(model2, 2.0, input, opt.crop_size, opt.batch_size)
  191. end
  192. end
  193. t = sys.clock()
  194. model1_output = scale_f(model1, 2.0, input, opt.crop_size, opt.batch_size)
  195. model1_time = model1_time + (sys.clock() - t)
  196. if model2 then
  197. t = sys.clock()
  198. model2_output = scale_f(model2, 2.0, input, opt.crop_size, opt.batch_size)
  199. model2_time = model2_time + (sys.clock() - t)
  200. end
  201. baseline_output = baseline_scale(input, opt.baseline_filter)
  202. elseif opt.method == "noise" then
  203. input = transform_jpeg(x[i].y, opt)
  204. ground_truth = x[i].y
  205. if opt.force_cudnn and i == 1 then
  206. model1_output = image_f(model1, input, opt.crop_size, opt.batch_size)
  207. if model2 then
  208. model2_output = image_f(model2, input, opt.crop_size, opt.batch_size)
  209. end
  210. end
  211. t = sys.clock()
  212. model1_output = image_f(model1, input, opt.crop_size, opt.batch_size)
  213. model1_time = model1_time + (sys.clock() - t)
  214. if model2 then
  215. t = sys.clock()
  216. model2_output = image_f(model2, input, opt.crop_size, opt.batch_size)
  217. model2_time = model2_time + (sys.clock() - t)
  218. end
  219. baseline_output = input
  220. elseif opt.method == "noise_scale" then
  221. input = transform_scale_jpeg(x[i].y, opt)
  222. ground_truth = x[i].y
  223. if opt.force_cudnn and i == 1 then
  224. if model1.noise_scale_model then
  225. model1_output = scale_f(model1.noise_scale_model, 2.0,
  226. input, opt.crop_size, opt.batch_size)
  227. else
  228. if model1.noise_model then
  229. model1_output = image_f(model1.noise_model, input, opt.crop_size, opt.batch_size)
  230. else
  231. model1_output = input
  232. end
  233. model1_output = scale_f(model1.scale_model, 2.0, model1_output,
  234. opt.crop_size, opt.batch_size)
  235. end
  236. if model2 then
  237. if model2.noise_scale_model then
  238. model2_output = scale_f(model2.noise_scale_model, 2.0,
  239. input, opt.crop_size, opt.batch_size)
  240. else
  241. if model2.noise_model then
  242. model2_output = image_f(model2.noise_model, input,
  243. opt.crop_size, opt.batch_size)
  244. else
  245. model2_output = input
  246. end
  247. model2_output = scale_f(model2.scale_model, 2.0, model2_output,
  248. opt.crop_size, opt.batch_size)
  249. end
  250. end
  251. end
  252. t = sys.clock()
  253. if model1.noise_scale_model then
  254. model1_output = scale_f(model1.noise_scale_model, 2.0,
  255. input, opt.crop_size, opt.batch_size)
  256. else
  257. if model1.noise_model then
  258. model1_output = image_f(model1.noise_model, input, opt.crop_size, opt.batch_size)
  259. else
  260. model1_output = input
  261. end
  262. model1_output = scale_f(model1.scale_model, 2.0, model1_output,
  263. opt.crop_size, opt.batch_size)
  264. end
  265. model1_time = model1_time + (sys.clock() - t)
  266. if model2 then
  267. t = sys.clock()
  268. if model2.noise_scale_model then
  269. model2_output = scale_f(model2.noise_scale_model, 2.0,
  270. input, opt.crop_size, opt.batch_size)
  271. else
  272. if model2.noise_model then
  273. model2_output = image_f(model2.noise_model, input,
  274. opt.crop_size, opt.batch_size)
  275. else
  276. model2_output = input
  277. end
  278. model2_output = scale_f(model2.scale_model, 2.0, model2_output,
  279. opt.crop_size, opt.batch_size)
  280. end
  281. model2_time = model2_time + (sys.clock() - t)
  282. end
  283. baseline_output = baseline_scale(input, opt.baseline_filter)
  284. elseif opt.method == "user" then
  285. input = x[i].x
  286. ground_truth = x[i].y
  287. local y_scale = ground_truth:size(2) / input:size(2)
  288. if y_scale > 1 then
  289. if opt.force_cudnn and i == 1 then
  290. model1_output = scale_f(model1, y_scale, input, opt.crop_size, opt.batch_size)
  291. if model2 then
  292. model2_output = scale_f(model2, y_scale, input, opt.crop_size, opt.batch_size)
  293. end
  294. end
  295. t = sys.clock()
  296. model1_output = scale_f(model1, y_scale, input, opt.crop_size, opt.batch_size)
  297. model1_time = model1_time + (sys.clock() - t)
  298. if model2 then
  299. t = sys.clock()
  300. model2_output = scale_f(model2, y_scale, input, opt.crop_size, opt.batch_size)
  301. model2_time = model2_time + (sys.clock() - t)
  302. end
  303. else
  304. if opt.force_cudnn and i == 1 then
  305. model1_output = image_f(model1, input, opt.crop_size, opt.batch_size)
  306. if model2 then
  307. model2_output = image_f(model2, input, opt.crop_size, opt.batch_size)
  308. end
  309. end
  310. t = sys.clock()
  311. model1_output = image_f(model1, input, opt.crop_size, opt.batch_size)
  312. model1_time = model1_time + (sys.clock() - t)
  313. if model2 then
  314. t = sys.clock()
  315. model2_output = image_f(model2, input, opt.crop_size, opt.batch_size)
  316. model2_time = model2_time + (sys.clock() - t)
  317. end
  318. end
  319. end
  320. mse = MSE(ground_truth, model1_output, opt.color)
  321. model1_mse = model1_mse + mse
  322. model1_psnr = model1_psnr + MSE2PSNR(mse)
  323. if model2 then
  324. mse = MSE(ground_truth, model2_output, opt.color)
  325. model2_mse = model2_mse + mse
  326. model2_psnr = model2_psnr + MSE2PSNR(mse)
  327. end
  328. if baseline_output then
  329. mse = MSE(ground_truth, baseline_output, opt.color)
  330. baseline_mse = baseline_mse + mse
  331. baseline_psnr = baseline_psnr + MSE2PSNR(mse)
  332. end
  333. if opt.save_image then
  334. if opt.save_baseline_image and baseline_output then
  335. image.save(path.join(opt.output_dir, string.format("%s_baseline.png", basename)),
  336. baseline_output)
  337. end
  338. if model1_output then
  339. image.save(path.join(opt.output_dir, string.format("%s_model1.png", basename)),
  340. model1_output)
  341. end
  342. if model2_output then
  343. image.save(path.join(opt.output_dir, string.format("%s_model2.png", basename)),
  344. model2_output)
  345. end
  346. end
  347. if opt.show_progress or i == #x then
  348. if model2 then
  349. if baseline_output then
  350. io.stdout:write(
  351. string.format("%d/%d; model1_time=%.2f, model2_time=%.2f, baseline_rmse=%f, model1_rmse=%f, model2_rmse=%f, baseline_psnr=%f, model1_psnr=%f, model2_psnr=%f \r",
  352. i, #x,
  353. model1_time,
  354. model2_time,
  355. math.sqrt(baseline_mse / i),
  356. math.sqrt(model1_mse / i), math.sqrt(model2_mse / i),
  357. baseline_psnr / i,
  358. model1_psnr / i, model2_psnr / i
  359. ))
  360. else
  361. io.stdout:write(
  362. string.format("%d/%d; model1_time=%.2f, model2_time=%.2f, model1_rmse=%f, model2_rmse=%f, model1_psnr=%f, model2_psnr=%f \r",
  363. i, #x,
  364. model1_time,
  365. model2_time,
  366. math.sqrt(model1_mse / i), math.sqrt(model2_mse / i),
  367. model1_psnr / i, model2_psnr / i
  368. ))
  369. end
  370. else
  371. if baseline_output then
  372. io.stdout:write(
  373. string.format("%d/%d; model1_time=%.2f, baseline_rmse=%f, model1_rmse=%f, baseline_psnr=%f, model1_psnr=%f \r",
  374. i, #x,
  375. model1_time,
  376. math.sqrt(baseline_mse / i), math.sqrt(model1_mse / i),
  377. baseline_psnr / i, model1_psnr / i
  378. ))
  379. else
  380. io.stdout:write(
  381. string.format("%d/%d; model1_time=%.2f, model1_rmse=%f, model1_psnr=%f \r",
  382. i, #x,
  383. model1_time,
  384. math.sqrt(model1_mse / i), model1_psnr / i
  385. ))
  386. end
  387. end
  388. io.stdout:flush()
  389. end
  390. end
  391. if opt.save_info then
  392. local fp = io.open(path.join(opt.output_dir, "benchmark.txt"), "w")
  393. fp:write("options : " .. cjson.encode(opt) .. "\n")
  394. if baseline_psnr > 0 then
  395. fp:write(string.format("baseline: RMSE = %.3f, PSNR = %.3f\n",
  396. math.sqrt(baseline_mse / #x), baseline_psnr / #x))
  397. end
  398. if model1_psnr > 0 then
  399. fp:write(string.format("model1 : RMSE = %.3f, PSNR = %.3f, evaluation time = %.3f\n",
  400. math.sqrt(model1_mse / #x), model1_psnr / #x, model1_time))
  401. end
  402. if model2_psnr > 0 then
  403. fp:write(string.format("model2 : RMSE = %.3f, PSNR = %.3f, evaluation time = %.3f\n",
  404. math.sqrt(model2_mse / #x), model2_psnr / #x, model2_time))
  405. end
  406. fp:close()
  407. end
  408. io.stdout:write("\n")
  409. end
  410. local function load_data(test_dir)
  411. local test_x = {}
  412. local files = dir.getfiles(test_dir, "*.*")
  413. for i = 1, #files do
  414. local name = path.basename(files[i])
  415. local e = path.extension(name)
  416. local base = name:sub(0, name:len() - e:len())
  417. local img = image_loader.load_float(files[i])
  418. if img then
  419. table.insert(test_x, {y = iproc.crop_mod4(img),
  420. basename = base})
  421. end
  422. if opt.show_progress then
  423. xlua.progress(i, #files)
  424. end
  425. end
  426. return test_x
  427. end
  428. local function get_basename(f)
  429. local name = path.basename(f)
  430. local e = path.extension(name)
  431. local base = name:sub(0, name:len() - e:len())
  432. return base
  433. end
  434. local function load_user_data(y_dir, x_dir)
  435. local test = {}
  436. local y_files = dir.getfiles(y_dir, "*.*")
  437. local x_files = dir.getfiles(x_dir, "*.*")
  438. local basename_db = {}
  439. for i = 1, #y_files do
  440. basename_db[get_basename(y_files[i])] = {y = y_files[i]}
  441. end
  442. for i = 1, #x_files do
  443. local key = get_basename(x_files[i])
  444. if basename_db[key] then
  445. basename_db[key].x = x_files[i]
  446. else
  447. error(string.format("%s is not found in %s", key, y_dir))
  448. end
  449. end
  450. for i = 1, #y_files do
  451. local key = get_basename(y_files[i])
  452. local d = basename_db[key]
  453. if not (d.x and d.y) then
  454. error(string.format("%s is not found in %s", key, x_dir))
  455. end
  456. end
  457. for i = 1, #y_files do
  458. local key = get_basename(y_files[i])
  459. local x = image_loader.load_float(basename_db[key].x)
  460. local y = image_loader.load_float(basename_db[key].y)
  461. if x and y then
  462. table.insert(test, {y = y,
  463. x = x,
  464. basename = base})
  465. end
  466. if opt.show_progress then
  467. xlua.progress(i, #y_files)
  468. end
  469. end
  470. return test
  471. end
  472. function load_noise_scale_model(model_dir, noise_level, force_cudnn)
  473. local f = path.join(model_dir, string.format("noise%d_scale2.0x_model.t7", opt.noise_level))
  474. local s1, noise_scale = pcall(w2nn.load_model, f, force_cudnn)
  475. local model = {}
  476. if not s1 then
  477. f = path.join(model_dir, string.format("noise%d_model.t7", opt.noise_level))
  478. local noise
  479. s1, noise = pcall(w2nn.load_model, f, force_cudnn)
  480. if not s1 then
  481. model.noise_model = nil
  482. print(model_dir .. "'s noise model is not found. benchmark will use only scale model.")
  483. else
  484. model.noise_model = noise
  485. end
  486. f = path.join(model_dir, "scale2.0x_model.t7")
  487. local scale
  488. s1, scale = pcall(w2nn.load_model, f, force_cudnn)
  489. if not s1 then
  490. error(model_dir .. ": load error")
  491. return nil
  492. end
  493. model.scale_model = scale
  494. else
  495. model.noise_scale_model = noise_scale
  496. end
  497. return model
  498. end
  499. if opt.show_progress then
  500. print(opt)
  501. end
  502. if opt.method == "scale" then
  503. local f1 = path.join(opt.model1_dir, "scale2.0x_model.t7")
  504. local f2 = path.join(opt.model2_dir, "scale2.0x_model.t7")
  505. local s1, model1 = pcall(w2nn.load_model, f1, opt.force_cudnn)
  506. local s2, model2 = pcall(w2nn.load_model, f2, opt.force_cudnn)
  507. if not s1 then
  508. error("Load error: " .. f1)
  509. end
  510. if not s2 then
  511. model2 = nil
  512. end
  513. local test_x = load_data(opt.dir)
  514. benchmark(opt, test_x, model1, model2)
  515. elseif opt.method == "noise" then
  516. local f1 = path.join(opt.model1_dir, string.format("noise%d_model.t7", opt.noise_level))
  517. local f2 = path.join(opt.model2_dir, string.format("noise%d_model.t7", opt.noise_level))
  518. local s1, model1 = pcall(w2nn.load_model, f1, opt.force_cudnn)
  519. local s2, model2 = pcall(w2nn.load_model, f2, opt.force_cudnn)
  520. if not s1 then
  521. error("Load error: " .. f1)
  522. end
  523. if not s2 then
  524. model2 = nil
  525. end
  526. local test_x = load_data(opt.dir)
  527. benchmark(opt, test_x, model1, model2)
  528. elseif opt.method == "noise_scale" then
  529. local model2 = nil
  530. local model1 = load_noise_scale_model(opt.model1_dir, opt.noise_level, opt.force_cudnn)
  531. if opt.model2_dir:len() > 0 then
  532. model2 = load_noise_scale_model(opt.model2_dir, opt.noise_level, opt.force_cudnn)
  533. end
  534. local test_x = load_data(opt.dir)
  535. benchmark(opt, test_x, model1, model2)
  536. elseif opt.method == "user" then
  537. local f1 = path.join(opt.model1_dir, string.format("%s_model.t7", opt.name))
  538. local f2 = path.join(opt.model2_dir, string.format("%s_model.t7", opt.name))
  539. local s1, model1 = pcall(w2nn.load_model, f1, opt.force_cudnn)
  540. local s2, model2 = pcall(w2nn.load_model, f2, opt.force_cudnn)
  541. if not s1 then
  542. error("Load error: " .. f1)
  543. end
  544. if not s2 then
  545. model2 = nil
  546. end
  547. local test = load_user_data(opt.y_dir, opt.x_dir)
  548. benchmark(opt, test, model1, model2)
  549. end