やりたいプログラムを実行したいです。
プログラムは
# -*- coding: utf-8 -*- #Copyright (c) 2017, Gabriel Eilertsen. #All rights reserved. import os, sys import tensorflow as tf 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: # Read frame 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') # Run prediction. # The gamma value is used to allow for boosting/reducing the intensity of # the reconstructed highlights. If y = f(x) is the reconstruction, the gamma # g alters this according to 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") # Gamma corrected output y_gamma = np.power(np.maximum(y_predict, 0.0), 0.5) # Write to disc 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()
です。実行したら
$ python3 hdrcnn_predict.py -h Traceback (most recent call last): File "hdrcnn_predict.py", line 28, in <module> FLAGS = tf.flags.FLAGS AttributeError: module 'tensorflow' has no attribute 'flags'
となってしまいました。
原因を調べたところ
https://github.com/tensorflow/tensor2tensor/issues/1754
で、tensorflow2.0をサポートしてないとあったので、
$ pip freeze | grep tensor tensorboard==1.15.0 tensorboard-data-server==0.6.1 tensorboard-plugin-wit==1.8.0 tensorflow==1.15.3 tensorflow-estimator==1.15.1 tensorlayer==1.11.1
にしたところ、
$ python3 hdrcnn_predict.py -h Traceback (most recent call last): File "hdrcnn_predict.py", line 4, in <module> import tensorflow as tf File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorflow/__init__.py", line 102, in <module> from tensorflow_core import * File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorflow_core/__init__.py", line 36, in <module> from tensorflow._api.v1 import compat File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorflow_core/_api/v1/compat/__init__.py", line 23, in <module> from tensorflow._api.v1.compat import v1 File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorflow_core/_api/v1/compat/v1/__init__.py", line 672, in <module> from tensorflow_estimator.python.estimator.api._v1 import estimator File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorflow_estimator/__init__.py", line 10, in <module> from tensorflow_estimator._api.v1 import estimator File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorflow_estimator/_api/v1/estimator/__init__.py", line 12, in <module> from tensorflow_estimator._api.v1.estimator import inputs File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorflow_estimator/_api/v1/estimator/inputs/__init__.py", line 10, in <module> from tensorflow_estimator.python.estimator.inputs.numpy_io import numpy_input_fn File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorflow_estimator/python/estimator/inputs/numpy_io.py", line 26, in <module> from tensorflow_estimator.python.estimator.inputs.queues import feeding_functions File "/Users/1831083/Library/Python/3.7/lib/python/site-packages/tensorflow_estimator/python/estimator/inputs/queues/feeding_functions.py", line 40, in <module> import pandas as pd File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/__init__.py", line 22, in <module> from pandas.compat import ( File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/compat/__init__.py", line 15, in <module> from pandas.compat.numpy import ( File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/compat/numpy/__init__.py", line 7, in <module> from pandas.util.version import Version File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/util/__init__.py", line 1, in <module> from pandas.util._decorators import ( # noqa File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/util/_decorators.py", line 14, in <module> from pandas._libs.properties import cache_readonly # noqa File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/_libs/__init__.py", line 13, in <module> from pandas._libs.interval import Interval File "pandas/_libs/interval.pyx", line 1, in init pandas._libs.interval ValueError: numpy.ufunc size changed, may indicate binary incompatibility. Expected 216 from C header, got 192 from PyObject
となってしまいました。
どうすればいいのかおしえてください。
よろしくお願い致します。
回答2件
あなたの回答
tips
プレビュー