質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
MacOS(OSX)

MacOSとは、Appleの開発していたGUI(グラフィカルユーザーインターフェース)を採用したオペレーションシステム(OS)です。Macintoshと共に、市場に出てGUIの普及に大きく貢献しました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

2回答

2420閲覧

TensorFlow2.*の'flags'の使い方を教えてください。

退会済みユーザー

退会済みユーザー

総合スコア0

MacOS(OSX)

MacOSとは、Appleの開発していたGUI(グラフィカルユーザーインターフェース)を採用したオペレーションシステム(OS)です。Macintoshと共に、市場に出てGUIの普及に大きく貢献しました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2021/08/17 08:57

編集2021/08/18 08:57

最初に書かせていただくのですが、TensorFlow2.*でtf.flagsが使用できないのは知っています。

自分がお聞きしたいのは、バージョンが変わりflagsの代わりがありそうなのでその使い方をお聞きしたくて質問しました。
こちらのサイトでは

主要な変更

API掃除
tf.app, tf.flags, tf.logging → absl-py

となっており、tf.flagsがabsl-pyでできると思いました。

こちらのサイトを参考にtf.flagsをflagsに変更していきました。

そしたら下記のようなエラーが出てきました

$ python3 hdrcnn_predict.py -h Traceback (most recent call last): File "hdrcnn_predict.py", line 43, in <module> sx = int(np.maximum(32, np.round(FLAGS.width/32.0)*32)) File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/absl/flags/_flagvalues.py", line 499, in __getattr__ raise _exceptions.UnparsedFlagAccessError(error_message) absl.flags._exceptions.UnparsedFlagAccessError: Trying to access flag --width before flags were parsed.

in getattr

raise _exceptions.UnparsedFlagAccessError(error_message)

このエラーは、2つ目のこちらのサイトの下に解決策が書かれており、

解決策:main関数を直接呼び出していないですか?app.run(main)の形で呼び出しましょう。

とあったので、とりあえずapp.run(main)を入れたところ

Python

1# -*- coding: utf-8 -*- 2 3#Copyright (c) 2017, Gabriel Eilertsen. 4#All rights reserved. 5 6import os, sys 7import tensorflow as tf 8import tensorlayer as tl 9import numpy as np 10import network, img_io 11 12from absl import app 13from absl import flags 14 15app.run(main) 16 17eps = 1e-5 18 19def print_(str, color='', bold=False): 20 if color == 'w': 21 sys.stdout.write('\033[93m') 22 elif color == "e": 23 sys.stdout.write('\033[91m') 24 elif color == "m": 25 sys.stdout.write('\033[95m') 26 27 if bold: 28 sys.stdout.write('\033[1m') 29 30 sys.stdout.write(str) 31 sys.stdout.write('\033[0m') 32 sys.stdout.flush() 33 34 35#設定、TensorFlow引数を使用 36FLAGS = flags.FLAGS 37flags.DEFINE_integer("width", "1024", "Reconstruction image width") 38flags.DEFINE_integer("height", "768", "Reconstruction image height") 39flags.DEFINE_string("im_dir", "data", "Path to image directory or an individual image") 40flags.DEFINE_string("out_dir", "out", "Path to output directory") 41flags.DEFINE_string("params", "hdrcnn_params.npz", "Path to trained CNN weights") 42 43flags.DEFINE_float("scaling", "1.0", "Pre-scaling, which is followed by clipping, in order to remove compression artifacts close to highlights") 44flags.DEFINE_float("gamma", "1.0", "Gamma/exponential curve applied before, and inverted after, prediction. This can be used to control the boost of reconstructed pixels.") 45 46#32の倍数に丸めて、オートエンコーダのプーリングとアップサンプリングを行う 47#入力画像と同じサイズになります 48sx = int(np.maximum(32, np.round(FLAGS.width/32.0)*32)) 49sy = int(np.maximum(32, np.round(FLAGS.height/32.0)*32)) 50if sx != FLAGS.width or sy != FLAGS.height: 51 print_("Warning: ", 'w', True) 52 print_("prediction size has been changed from %dx%d pixels to %dx%d\n"%(FLAGS.width, FLAGS.height, sx, sy), 'w') 53 print_("ピクセル、オートエンコーダのプーリングとアップサンプリングに準拠します。\n\n", 'w') 54 55#情報 56print_("\n\n\t-------------------------------------------------------------------\n", 'm') 57print_("\t ディープCNNを使用した単一露光からのHDR画像再構成\n\n", 'm') 58print_("\t 予測設定\n", 'm') 59print_("\t -------------------\n", 'm') 60print_("\t 入力画像のディレクトリ/ファイル:%s\n" % FLAGS.im_dir, 'm') 61print_("\t 出力ディレクトリ:%s\n" % FLAGS.out_dir, 'm') 62print_("\t CNN重み:%s\n" % FLAGS.params, 'm') 63print_("\t 予測解像度: %dx%d ピクセル\n" % (sx, sy), 'm') 64if FLAGS.scaling > 1.0: 65 print_("\t Pre-scaling: %0.4f\n" % FLAGS.scaling, 'm') 66if FLAGS.gamma > 1.0 + eps or FLAGS.gamma < 1.0 - eps: 67 print_("\t Gamma: %0.4f\n" % FLAGS.gamma, 'm') 68print_("\t-------------------------------------------------------------------\n\n\n", 'm') 69 70# シングルフレーム 71frames = [FLAGS.im_dir] 72 73# ディレクトリが指定されている場合は、パス内のすべてのファイルの名前を取得します 74if os.path.isdir(FLAGS.im_dir): 75 frames = [os.path.join(FLAGS.im_dir, name) 76 for name in sorted(os.listdir(FLAGS.im_dir)) 77 if os.path.isfile(os.path.join(FLAGS.im_dir, name))] 78 79#画像入力用のプレースホルダー 80x = tf.placeholder(tf.float32, shape=[1, sy, sx, 3]) 81 82#HDR再構成オートエンコーダモデル 83print_("Network setup:\n") 84net = network.model(x) 85 86#CNN予測(これには入力画像xとのブレンドも含まれます) 87y = network.get_final(net, x) 88 89#推論を実行するためのTensorFlowセッション 90sess = tf.InteractiveSession() 91 92#トレーニング済みのCNNウェイトをロードする 93print_("\nLoading trained parameters from '%s'..."%FLAGS.params) 94load_params = tl.files.load_npz(name=FLAGS.params) 95tl.files.assign_params(sess, load_params, net) 96print_("\tdone\n") 97 98if not os.path.exists(FLAGS.out_dir): 99 os.makedirs(FLAGS.out_dir) 100 101print_("\nStarting prediction...\n\n") 102k = 0 103for i in range(len(frames)): 104 print("Frame %d: '%s'"%(i,frames[i])) 105 106 try: 107 #フレームの読み込み 108 print_("\tReading...") 109 x_buffer = img_io.readLDR(frames[i], (sy,sx), True, FLAGS.scaling) 110 print_("\tdone") 111 112 print_("\t(Saturation: %0.2f%%)\n" % (100.0*(x_buffer>=1).sum()/x_buffer.size), 'm') 113 114 # 実行予測。 115 # ガンマ値は、再構成されたハイライトの強度を高める/減らすことを可能にするために使用されます。 116 # y = f(x)が再構成されたものであれば、ガンマ値 gは、y = f(x^(1/g))^gに従ってこれを変更します。 117 print_("\tInference...") 118 feed_dict = {x: np.power(np.maximum(x_buffer, 0.0), 1.0/FLAGS.gamma)} 119 y_predict = sess.run([y], feed_dict=feed_dict) 120 y_predict = np.power(np.maximum(y_predict, 0.0), FLAGS.gamma) 121 print_("\tdone\n") 122 123 # ガンマ補正出力 124 y_gamma = np.power(np.maximum(y_predict, 0.0), 0.5) 125 126 # ディスクへの書き込み 127 print_("\tWriting...") 128 k += 1; 129 img_io.writeLDR(x_buffer, '%s/%06d_in.png' % (FLAGS.out_dir, k), -3) 130 img_io.writeLDR(y_gamma, '%s/%06d_out.png' % (FLAGS.out_dir, k), -3) 131 img_io.writeEXR(y_predict, '%s/%06d_out.exr' % (FLAGS.out_dir, k)) 132 print_("\tdone\n") 133 134 except img_io.IOException as e: 135 print_("\n\t\tWarning! ", 'w', True) 136 print_("%s\n"%e, 'w') 137 except Exception as e: 138 print_("\n\t\tError: ", 'e', True) 139 print_("%s\n"%e, 'e') 140 141print_("Done!\n") 142 143sess.close()

Traceback (most recent call last):

File "hdrcnn_predict.py", line 12, in <module>
app.run(main)
NameError: name 'main' is not defined

となってしまいました。

このプログラムに元々mainがないので、app.run(main)の入れ方が分かりません。
どうしたら良いのでしょうか?

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

jbpb0

2021/08/17 10:31 編集

https://github.com/gabrieleilertsen/hdrcnn のオリジナルのコード(質問者さんが修正してないもの)で、 import tensorflow as tf ↓ 変更 import tensorflow.compat.v1 as tf tf.disable_v2_behavior() のみ変更して、他はオリジナルのままで、TensorFlow 2.*で実行したら、どうなりますか? 参考 https://qiita.com/rawHam/items/626d9b119cbefcee1452 の「3. 2系挙動を無効化する」 ただし、TensorLayer他いろいろは、TF 2.*に対応したものが入ってる必要がありますが
退会済みユーザー

退会済みユーザー

2021/08/17 10:16

from absl import app from absl import flags のところで変更した所を 元に戻して変更して実行するという解釈で大丈夫でしょうか?
jbpb0

2021/08/17 10:18

質問者さんが変えたところを戻すと、戻し忘れがあるかもしれないので、本当のオリジナルから作り直した方が確実だと思います
退会済みユーザー

退会済みユーザー

2021/08/18 05:43

変更したら WARNING:tensorflow:From /Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorflow/python/compat/v2_compat.py:101: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Instructions for updating: non-resource variables are not supported in the long term Traceback (most recent call last): File "hdrcnn_predict.py", line 41, in <module> sx = int(np.maximum(32, np.round(FLAGS.width/32.0)*32)) File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorflow/python/platform/flags.py", line 85, in __getattr__ wrapped(_sys.argv) File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/absl/flags/_flagvalues.py", line 670, in __call__ name, value, suggestions=suggestions) absl.flags._exceptions.UnrecognizedFlagError: Unknown command line flag 'h' になりました
jbpb0

2021/08/18 07:38 編集

> Unknown command line flag 'h' って、おそらく > python3 hdrcnn_predict.py -h の「-h」なんて知らないよ、って言ってるのだと思います 詳細分かりませんが、TF 2.* の互換モードでは「-h」が無くなったのかもしれません 「-h」ではなく「--help」でもダメでしょうか? 「--help」でもダメなら、 https://github.com/gabrieleilertsen/hdrcnn/blob/master/hdrcnn_predict.py の「# Settings, using TensorFlow arguments」と書いてるところから下にオプションが書かれてるので、そこ見たらオプションの指定のやり方が分かると思います あと、 https://github.com/gabrieleilertsen/hdrcnn の「Usage」の「Example」のところを参照するとか
jbpb0

2021/08/18 08:04

https://teratail.com/questions/354950 の質問のコードでは「def main():」とかやってますけど、上記の「変更したら...」は、それやらないオリジナルのコードに、 import tensorflow as tf ↓ 変更 import tensorflow.compat.v1 as tf tf.disable_v2_behavior() だけやった場合の話ですよね?
退会済みユーザー

退会済みユーザー

2021/08/18 08:10

プログラムを3つに分けて、原文と、変更、abslに変更の3つでやっています。 なので、ここの質問のところでは import tensorflow as tf ↓ 変更 import tensorflow.compat.v1 as tf tf.disable_v2_behavior() だけやった場合です。 今新たに質問した方は、abslを使った場合のプログラムです。
退会済みユーザー

退会済みユーザー

2021/08/18 08:11

# -*- coding: utf-8 -*- import os, sys import tensorflow.compat.v1 as tf tf.disable_v2_behavior() import tensorlayer as tl import numpy as np import network, img_io eps = 1e-5 def print_(str, color='', bold=False): if color == 'w': sys.stdout.write('\033[93m') elif color == "e": sys.stdout.write('\033[91m') elif color == "m": sys.stdout.write('\033[95m') if bold: sys.stdout.write('\033[1m') sys.stdout.write(str) sys.stdout.write('\033[0m') sys.stdout.flush() #設定、TensorFlow引数を使用 FLAGS = tf.flags.FLAGS tf.flags.DEFINE_integer("width", "1024", "Reconstruction image width") tf.flags.DEFINE_integer("height", "768", "Reconstruction image height") tf.flags.DEFINE_string("im_dir", "data", "Path to image directory or an individual image") tf.flags.DEFINE_string("out_dir", "out", "Path to output directory") tf.flags.DEFINE_string("params", "hdrcnn_params.npz", "Path to trained CNN weights") tf.flags.DEFINE_float("scaling", "1.0", "Pre-scaling, which is followed by clipping, in order to remove compression artifacts close to highlights") tf.flags.DEFINE_float("gamma", "1.0", "Gamma/exponential curve applied before, and inverted after, prediction. This can be used to control the boost of reconstructed pixels.") #32の倍数に丸めて、オートエンコーダのプーリングとアップサンプリングを行う #入力画像と同じサイズになります sx = int(np.maximum(32, np.round(FLAGS.width/32.0)*32)) sy = int(np.maximum(32, np.round(FLAGS.height/32.0)*32)) if sx != FLAGS.width or sy != FLAGS.height: print_("Warning: ", 'w', True) print_("prediction size has been changed from %dx%d pixels to %dx%d\n"%(FLAGS.width, FLAGS.height, sx, sy), 'w') print_("ピクセル、オートエンコーダのプーリングとアップサンプリングに準拠します。\n\n", 'w') #情報 print_("\n\n\t-------------------------------------------------------------------\n", 'm') print_("\t ディープCNNを使用した単一露光からのHDR画像再構成\n\n", 'm') print_("\t 予測設定\n", 'm') print_("\t -------------------\n", 'm') print_("\t 入力画像のディレクトリ/ファイル:%s\n" % FLAGS.im_dir, 'm') print_("\t 出力ディレクトリ:%s\n" % FLAGS.out_dir, 'm') print_("\t CNN重み:%s\n" % FLAGS.params, 'm') print_("\t 予測解像度: %dx%d ピクセル\n" % (sx, sy), 'm') if FLAGS.scaling > 1.0: print_("\t Pre-scaling: %0.4f\n" % FLAGS.scaling, 'm') if FLAGS.gamma > 1.0 + eps or FLAGS.gamma < 1.0 - eps: print_("\t Gamma: %0.4f\n" % FLAGS.gamma, 'm') print_("\t-------------------------------------------------------------------\n\n\n", 'm') # シングルフレーム frames = [FLAGS.im_dir] # ディレクトリが指定されている場合は、パス内のすべてのファイルの名前を取得します if os.path.isdir(FLAGS.im_dir): frames = [os.path.join(FLAGS.im_dir, name) for name in sorted(os.listdir(FLAGS.im_dir)) if os.path.isfile(os.path.join(FLAGS.im_dir, name))] #画像入力用のプレースホルダー x = tf.placeholder(tf.float32, shape=[1, sy, sx, 3]) #HDR再構成オートエンコーダモデル print_("Network setup:\n") net = network.model(x) #CNN予測(これには入力画像xとのブレンドも含まれます) y = network.get_final(net, x) #推論を実行するためのTensorFlowセッション sess = tf.InteractiveSession() #トレーニング済みのCNNウェイトをロードする print_("\nLoading trained parameters from '%s'..."%FLAGS.params) load_params = tl.files.load_npz(name=FLAGS.params) tl.files.assign_params(sess, load_params, net) print_("\tdone\n") if not os.path.exists(FLAGS.out_dir): os.makedirs(FLAGS.out_dir) print_("\nStarting prediction...\n\n") k = 0 for i in range(len(frames)): print("Frame %d: '%s'"%(i,frames[i])) try: #フレームの読み込み print_("\tReading...") x_buffer = img_io.readLDR(frames[i], (sy,sx), True, FLAGS.scaling) print_("\tdone") print_("\t(Saturation: %0.2f%%)\n" % (100.0*(x_buffer>=1).sum()/x_buffer.size), 'm') # 実行予測。 # ガンマ値は、再構成されたハイライトの強度を高める/減らすことを可能にするために使用されます。 # y = f(x)が再構成されたものであれば、ガンマ値 gは、y = f(x^(1/g))^gに従ってこれを変更します。 print_("\tInference...") feed_dict = {x: np.power(np.maximum(x_buffer, 0.0), 1.0/FLAGS.gamma)} y_predict = sess.run([y], feed_dict=feed_dict) y_predict = np.power(np.maximum(y_predict, 0.0), FLAGS.gamma) print_("\tdone\n") # ガンマ補正出力 y_gamma = np.power(np.maximum(y_predict, 0.0), 0.5) # ディスクへの書き込み print_("\tWriting...") k += 1; img_io.writeLDR(x_buffer, '%s/%06d_in.png' % (FLAGS.out_dir, k), -3) img_io.writeLDR(y_gamma, '%s/%06d_out.png' % (FLAGS.out_dir, k), -3) img_io.writeEXR(y_predict, '%s/%06d_out.exr' % (FLAGS.out_dir, k)) print_("\tdone\n") except img_io.IOException as e: print_("\n\t\tWarning! ", 'w', True) print_("%s\n"%e, 'w') except Exception as e: print_("\n\t\tError: ", 'e', True) print_("%s\n"%e, 'e') print_("Done!\n") sess.close()
jbpb0

2021/08/18 08:17

> ここの質問のところでは import tensorflow as tf ↓ 変更 import tensorflow.compat.v1 as tf tf.disable_v2_behavior() だけやった場合です。 その場合でも、「--params...」付けたら https://teratail.com/questions/354950 で質問してるようなエラー出ます?
退会済みユーザー

退会済みユーザー

2021/08/18 08:23

$ python3 hdrcnn_predict.py --params hdrcnn_params4.npz --im_dir data --width 1024 --height 768 WARNING:tensorflow:From /Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorflow/python/compat/v2_compat.py:101: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Instructions for updating: non-resource variables are not supported in the long term ------------------------------------------------------------------- ディープCNNを使用した単一露光からのHDR画像再構成 予測設定 ------------------- 入力画像のディレクトリ/ファイル:data 出力ディレクトリ:out CNN重み:hdrcnn_params4.npz 予測解像度: 1024x768 ピクセル ------------------------------------------------------------------- Network setup: Traceback (most recent call last): File "hdrcnn_predict.py", line 77, in <module> net = network.model(x) File "/Users/1831083/hdrcnn/hdrcnn-master/network.py", line 49, in model net_in = tl.layers.InputLayer(x_in, name='input_layer') File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorlayer/layers/deprecated.py", line 178, in InputLayer raise NonExistingLayerError("InputLayer(x, name='a') --> Input(name='a')(x)" + __log__) tensorlayer.layers.deprecated.NonExistingLayerError: InputLayer(x, name='a') --> Input(name='a')(x) Hint: 1) downgrade TF and TL from version 2.x to 1.x. 2) check the documentation of TF and TL version 2.x 下に何かが出ました。
jbpb0

2021/08/18 08:36

network.py」も import tensorflow as tf ↓ 変更 import tensorflow.compat.v1 as tf tf.disable_v2_behavior() をやってください 「training_code」の「hdrcnn_train.py」も (使うなら)
退会済みユーザー

退会済みユーザー

2021/08/18 08:40

$ python3 hdrcnn_predict4.py --params hdrcnn_params.npz --im_dir data --width 1024 --height 768 WARNING:tensorflow:From /Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorflow/python/compat/v2_compat.py:101: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Instructions for updating: non-resource variables are not supported in the long term ------------------------------------------------------------------- ディープCNNを使用した単一露光からのHDR画像再構成 予測設定 ------------------- 入力画像のディレクトリ/ファイル:data 出力ディレクトリ:out CNN重み:hdrcnn_params.npz 予測解像度: 1024x768 ピクセル ------------------------------------------------------------------- Network setup: Traceback (most recent call last): File "hdrcnn_predict4.py", line 77, in <module> net = network.model(x) File "/Users/1831083/hdrcnn/hdrcnn-master/network.py", line 50, in model net_in = tl.layers.InputLayer(x_in, name='input_layer') File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorlayer/layers/deprecated.py", line 178, in InputLayer raise NonExistingLayerError("InputLayer(x, name='a') --> Input(name='a')(x)" + __log__) tensorlayer.layers.deprecated.NonExistingLayerError: InputLayer(x, name='a') --> Input(name='a')(x) Hint: 1) downgrade TF and TL from version 2.x to 1.x. 2) check the documentation of TF and TL version 2.x 変えたところこのようになりました。
jbpb0

2021/08/18 08:53

> InputLayer(x, name='a') --> Input(name='a')(x) と書かれてるように、「network.py」の50行目を変更してみてください net_in = tl.layers.InputLayer(x_in, name='input_layer') ↓ 変更 net_in = tl.layers.Input(name='input_layer')(x_in)
退会済みユーザー

退会済みユーザー

2021/08/18 09:00

$ python3 hdrcnn_predict4.py --params hdrcnn_params.npz --im_dir data --width 1024 --height 768 WARNING:tensorflow:From /Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorflow/python/compat/v2_compat.py:101: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Instructions for updating: non-resource variables are not supported in the long term ------------------------------------------------------------------- ディープCNNを使用した単一露光からのHDR画像再構成 予測設定 ------------------- 入力画像のディレクトリ/ファイル:data 出力ディレクトリ:out CNN重み:hdrcnn_params.npz 予測解像度: 1024x768 ピクセル ------------------------------------------------------------------- Network setup: Traceback (most recent call last): File "hdrcnn_predict4.py", line 77, in <module> net = network.model(x) File "/Users/1831083/hdrcnn/hdrcnn-master/network.py", line 50, in model net_in = tl.layers.Input(name='input_layer')(x_in) TypeError: Input() missing 1 required positional argument: 'shape' でした。
jbpb0

2021/08/18 09:43

net_in = tl.layers.Input(tf.shape(x_in), name='input_layer')(x_in) かな?? (未確認)
退会済みユーザー

退会済みユーザー

2021/08/19 07:22

network.py」のline50を net_in = tl.layers.InputLayer(x_in, name='input_layer') ↓ net_in = tl.layers.Input(tf.shape(x_in), name='input_layer')(x_in) に変更したところ以下のようになりました。 $ python3 hdrcnn_predict4.py --params hdrcnn_params.npz --im_dir data --width 1024 --height 768 WARNING:tensorflow:From /Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorflow/python/compat/v2_compat.py:101: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Instructions for updating: non-resource variables are not supported in the long term ------------------------------------------------------------------- ディープCNNを使用した単一露光からのHDR画像再構成 予測設定 ------------------- 入力画像のディレクトリ/ファイル:data 出力ディレクトリ:out CNN重み:hdrcnn_params.npz 予測解像度: 1024x768 ピクセル ------------------------------------------------------------------- Network setup: Traceback (most recent call last): File "hdrcnn_predict4.py", line 77, in <module> net = network.model(x) File "/Users/1831083/hdrcnn/hdrcnn-master/network.py", line 50, in model net_in = tl.layers.Input(tf.shape(x_in), name='input_layer')(x_in) File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorlayer/layers/inputs.py", line 83, in Input input_layer = _InputLayer(shape, dtype=dtype, name=name) File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorlayer/layers/inputs.py", line 46, in __init__ shape_without_none = [_ if _ is not None else 1 for _ in shape] File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorflow/python/framework/ops.py", line 520, in __iter__ self._disallow_iteration() File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorflow/python/framework/ops.py", line 516, in _disallow_iteration self._disallow_in_graph_mode("iterating over `tf.Tensor`") File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorflow/python/framework/ops.py", line 496, in _disallow_in_graph_mode " this function with @tf.function.".format(task)) tensorflow.python.framework.errors_impl.OperatorNotAllowedInGraphError: iterating over `tf.Tensor` is not allowed in Graph execution. Use Eager execution or decorate this function with @tf.function.
jbpb0

2021/08/19 08:00 編集

https://github.com/gabrieleilertsen/hdrcnn は約4年前に書かれたもので、当時のTensorLayer 1.*用に書かれているのをTensorLayer 2.*で動かそうとしているので、仕様の違いで書き直さないといけないところが出てきてます https://teratail.com/questions/354950 の質問のコードのように「absl」を使うようにしても、TensorLayerを使うところは共通なので、そちらのコードで今出てるエラーを直したら、結局同じことが起きるはずです https://teratail.com/questions/354646 にも書きましたけど、仮想環境の中で4年前のバージョンに揃えた環境を再現して動かすというやり方もあります
jbpb0

2021/08/19 08:10

ここのもともとの質問 > TensorFlow2.*の'flags'の使い方を教えてください。 は、 import tensorflow as tf ↓ 変更 import tensorflow.compat.v1 as tf tf.disable_v2_behavior() でTF 2.*でも「tf.flags」が使えるので、解決してますよね 今出てるエラーは、TensorLayerの1.*と2.*の仕様の違いによるものなので、もともとの質問から大きく外れた内容なので、そのことについてさらに質問するのなら、ここで続けるのではなくて、別の質問にしてください
退会済みユーザー

退会済みユーザー

2021/08/19 08:17

そうですね。 回答していただければ幸いです。 このままこのプログラムをTensorFlow2.*で動かせるようにしたいのですがその場合の質問はどうしたら良いのか教えていただければ幸いです。
guest

回答2

0

Deep learning HDR image reconstruction
のオリジナルのコード(質問者さんが修正してないもの)から

python

1import tensorflow as tf

↓ 変更

python

1import tensorflow.compat.v1 as tf 2tf.disable_v2_behavior()

を行えば、

tf.flagsがabsl-pyでできると思いました。

tf.flagsをflagsに変更していきました。

をやらなくても

TensorFlow2.*でtf.flagsが使用できない

が解消されると思います

参考
Tensorflow 2で1系記法のCNNを動かす方法
の「3. 2系挙動を無効化する」

投稿2021/08/23 00:35

編集2021/08/23 00:37
jbpb0

総合スコア7651

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

ベストアンサー

Traceback (most recent call last):

File "hdrcnn_predict.py", line 12, in <module>
app.run(main)
NameError: name 'main' is not defined

関数 main を定義していないからでは?

Python

1print("Hello") 2...

Python

1def main(): 2 print("hello") 3 ... 4 5if __name__ == "__main__": 6 app.run(main)

って書けばいいかと。

投稿2021/08/17 09:31

編集2021/08/17 10:00
episteme

総合スコア16614

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2021/08/17 09:54

このプログラム、他のサイトから持ってきたものなので、このプログラムでのmainの書き方が分からないので、どう書けばいいのか教えて頂きたいのです。
episteme

2021/08/17 10:01

追記しました
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問