HDRNetを動かせたい。
コード:https://github.com/creotiv/hdrnet
環境:ubuntu18.04, python3.6, tensorflow-gpu==1.13.0
Build
- build operator
Test
1.py.test /test でコンパイルされたopをテストする時FATAL ERRORが出た。
if __name__ == "__main__":
tf.test.main()
をops_test.pyに追加、python ops_test.pyで実行したら通った。
Data
フォルダー組織
データフォルダーを
-root
-input
-output
filelist.txt
のように組織します。原則的にinputとoutputのペアの画像は同じ名前を持ち、filelistは一回だけ記録。
データセット
fivek: https://data.csail.mit.edu/graphics/fivek/
HDR+: https://hdrplusdata.org/dataset.html
HDR+は直接に使えるデータを提供していません。そのフローでraw imageを処理しなければなりません。
hdrnetの論文には16ビットのlinear space imageを使ってると書いてありますが、HDR+の論文には14ビットの画像だけ言及しました。具体的にはどんな画像なのかね?
https://github.com/cchen156/Learning-to-See-in-the-Dark/issues/29
こちらの人たちはraw imageを処理して16ビットを得られた。でも結果はあんまりよくない。
今回使ってるの16ビットpng画像とトンマッパされた8ビットpng画像。datapipelineのなかはnormalizationを行う。
Train
CUDA_VISIBLE_DEVICES=2 python ./hdrnet/bin/train.py \
--checkpoint_dir ./pretrained_models/reinhard2 \
--data_dir ./data/cityscapes/filelist.txt \
--learning_rate 1e-4 \
--batch_size 16 \
--flipud \
--fliplr \
--random_crop \
--data_pipeline ImageFilesDataPipeline \
--model_name HDRNetPointwiseNNGuide \
--net_input_size 512 \
--output_resolution 1024 2048 \ #画像のサイズ
--channel_multiplier $cm \
--eval_data_dir ./data/cityscapes/filelist_val.txt
なぜかoutput_resolutionのところはx<=yを要求、正方形の画像じゃないとrotateを使えません。
evalするため、train.pyを以下の通り修正
val_samples = eval_data_pipeline.samples
eval_samples = eval_samples.make_one_shot_iterator()
samples_eval = eval_samples.get_next()
…
if args.eval_data_dir is not None:
with tf.name_scope('eval'):
with tf.variable_scope('inference', reuse=True):
eval_prediction = mdl.inference(
samples_eval['lowres_input'], samples_eval['image_input'],
model_params, is_training=False)
eval_psnr = metrics.psnr(samples_eval['image_output'], eval_prediction)
一番いいモデルを保存する
step, _, = sess.run([global_step, train_op])
since_eval = time.time()-last_eval
val_psnr = sess.run(eval_psnr)
if val_psnr > best_val_psnr:
# Update the best-known validation accuracy.
best_val_psnr = val_psnr
# Set the iteration for the last improvement to current.
last_improvement = step
chkpt_path = os.path.join(args.checkpoint_dir, 'best/best{}.ckpt'.format(val_psnr))
log.info("PSNR improved, saving chkpt {}".format(chkpt_path))
sv.saver.save(sess, chkpt_path)
# If no improvement found in the required number of iterations.
if step - last_improvement > require_improvement:
print("No improvement found in a while, stopping optimization.")
# Break out from the for-loop.
break
Inference
エラー
Traceback (most recent call last):
File "./hdrnet/bin/run.py", line 243, in <module>
main(args)
File "./hdrnet/bin/run.py", line 99, in main
t_lowres_input, t_fullres_input, model_params, is_training=False)
File "./hdrnet/bin/../../hdrnet/models.py", line 47, in inference
bilateral_coeffs = cls._coefficients(lowres_input, params, is_training)
File "./hdrnet/bin/../../hdrnet/models.py", line 99, in _coefficients
scope="fc1")
File "./hdrnet/bin/../../hdrnet/layers.py", line 92, in fc
scope=scope)
File "/home/tzhong/.pyenv/versions/anaconda3-5.3.0/envs/tf1_13/lib/python3.6/site-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 182, in func_with_args
return func(*args, **current_args)
File "/home/tzhong/.pyenv/versions/anaconda3-5.3.0/envs/tf1_13/lib/python3.6/site-packages/tensorflow/contrib/layers/python/layers/layers.py", line 1828, in fully_connected
list(six.integer_types), type(num_outputs)))
ValueError: num_outputs type should be one of [<class 'int'>], got <class 'numpy.int64'>.
int(num_outputs)で強引に変換。