このプログラムを実行したところ下記のようなエラーが出てきました。
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 12eps = 1e-5 13 14def print_(str, color='', bold=False): 15 if color == 'w': 16 sys.stdout.write('\033[93m') 17 elif color == "e": 18 sys.stdout.write('\033[91m') 19 elif color == "m": 20 sys.stdout.write('\033[95m') 21 22 if bold: 23 sys.stdout.write('\033[1m') 24 25 sys.stdout.write(str) 26 sys.stdout.write('\033[0m') 27 sys.stdout.flush() 28 29 30#設定、TensorFlow引数を使用 31FLAGS = tf.flags.FLAGS 32tf.flags.DEFINE_integer("width", "1024", "Reconstruction image width") 33tf.flags.DEFINE_integer("height", "768", "Reconstruction image height") 34tf.flags.DEFINE_string("im_dir", "data", "Path to image directory or an individual image") 35tf.flags.DEFINE_string("out_dir", "out", "Path to output directory") 36tf.flags.DEFINE_string("params", "hdrcnn_params.npz", "Path to trained CNN weights") 37 38tf.flags.DEFINE_float("scaling", "1.0", "Pre-scaling, which is followed by clipping, in order to remove compression artifacts close to highlights") 39tf.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.") 40 41#32の倍数に丸めて、オートエンコーダのプーリングとアップサンプリングを行う 42#入力画像と同じサイズになります 43sx = int(np.maximum(32, np.round(FLAGS.width/32.0)*32)) 44sy = int(np.maximum(32, np.round(FLAGS.height/32.0)*32)) 45if sx != FLAGS.width or sy != FLAGS.height: 46 print_("Warning: ", 'w', True) 47 print_("prediction size has been changed from %dx%d pixels to %dx%d\n"%(FLAGS.width, FLAGS.height, sx, sy), 'w') 48 print_("ピクセル、オートエンコーダのプーリングとアップサンプリングに準拠します。\n\n", 'w') 49 50#情報 51print_("\n\n\t-------------------------------------------------------------------\n", 'm') 52print_("\t ディープCNNを使用した単一露光からのHDR画像再構成\n\n", 'm') 53print_("\t 予測設定\n", 'm') 54print_("\t -------------------\n", 'm') 55print_("\t 入力画像のディレクトリ/ファイル:%s\n" % FLAGS.im_dir, 'm') 56print_("\t 出力ディレクトリ:%s\n" % FLAGS.out_dir, 'm') 57print_("\t CNN重み:%s\n" % FLAGS.params, 'm') 58print_("\t 予測解像度: %dx%d ピクセル\n" % (sx, sy), 'm') 59if FLAGS.scaling > 1.0: 60 print_("\t Pre-scaling: %0.4f\n" % FLAGS.scaling, 'm') 61if FLAGS.gamma > 1.0 + eps or FLAGS.gamma < 1.0 - eps: 62 print_("\t Gamma: %0.4f\n" % FLAGS.gamma, 'm') 63print_("\t-------------------------------------------------------------------\n\n\n", 'm') 64 65# シングルフレーム 66frames = [FLAGS.im_dir] 67 68# ディレクトリが指定されている場合は、パス内のすべてのファイルの名前を取得します 69if os.path.isdir(FLAGS.im_dir): 70 frames = [os.path.join(FLAGS.im_dir, name) 71 for name in sorted(os.listdir(FLAGS.im_dir)) 72 if os.path.isfile(os.path.join(FLAGS.im_dir, name))] 73 74#画像入力用のプレースホルダー 75x = tf.placeholder(tf.float32, shape=[1, sy, sx, 3]) 76 77#HDR再構成オートエンコーダモデル 78print_("Network setup:\n") 79net = network.model(x) 80 81#CNN予測(これには入力画像xとのブレンドも含まれます) 82y = network.get_final(net, x) 83 84#推論を実行するためのTensorFlowセッション 85sess = tf.InteractiveSession() 86 87#トレーニング済みのCNNウェイトをロードする 88print_("\nLoading trained parameters from '%s'..."%FLAGS.params) 89load_params = tl.files.load_npz(name=FLAGS.params) 90tl.files.assign_params(sess, load_params, net) 91print_("\tdone\n") 92 93if not os.path.exists(FLAGS.out_dir): 94 os.makedirs(FLAGS.out_dir) 95 96print_("\nStarting prediction...\n\n") 97k = 0 98for i in range(len(frames)): 99 print("Frame %d: '%s'"%(i,frames[i])) 100 101 try: 102 # Read frame 103 print_("\tReading...") 104 x_buffer = img_io.readLDR(frames[i], (sy,sx), True, FLAGS.scaling) 105 print_("\tdone") 106 107 print_("\t(Saturation: %0.2f%%)\n" % (100.0*(x_buffer>=1).sum()/x_buffer.size), 'm') 108 109 # Run prediction. 110 # The gamma value is used to allow for boosting/reducing the intensity of 111 # the reconstructed highlights. If y = f(x) is the reconstruction, the gamma 112 # g alters this according to y = f(x^(1/g))^g 113 print_("\tInference...") 114 feed_dict = {x: np.power(np.maximum(x_buffer, 0.0), 1.0/FLAGS.gamma)} 115 y_predict = sess.run([y], feed_dict=feed_dict) 116 y_predict = np.power(np.maximum(y_predict, 0.0), FLAGS.gamma) 117 print_("\tdone\n") 118 119 # Gamma corrected output 120 y_gamma = np.power(np.maximum(y_predict, 0.0), 0.5) 121 122 # Write to disc 123 print_("\tWriting...") 124 k += 1; 125 img_io.writeLDR(x_buffer, '%s/%06d_in.png' % (FLAGS.out_dir, k), -3) 126 img_io.writeLDR(y_gamma, '%s/%06d_out.png' % (FLAGS.out_dir, k), -3) 127 img_io.writeEXR(y_predict, '%s/%06d_out.exr' % (FLAGS.out_dir, k)) 128 print_("\tdone\n") 129 130 except img_io.IOException as e: 131 print_("\n\t\tWarning! ", 'w', True) 132 print_("%s\n"%e, 'w') 133 except Exception as e: 134 print_("\n\t\tError: ", 'e', True) 135 print_("%s\n"%e, 'e') 136 137print_("Done!\n") 138 139sess.close()
Traceback (most recent call last): File "hdrcnn_predict.py", line 4, in <module> import tensorflow as tf ImportError: No module named tensorflow
Traceback (most recent call last): ファイル "hdrcnn_predict.py", line 4, in <module>. tensorflow を tf としてインポート ImportErrorが発生しました。tensorflow という名前のモジュールがありません。
と言われてしまったので、最初に
pip install tensorflow
と行い実行したのですが、エラーが変わりませんでした。pip3も同じでした。
pip uninstall tensorflow
pip install tensorflow
としてもダメでした。
自分の環境はこの通りです。
MACのターミナルで実行してます。
$ python -V
Python 2.7.16
$ python3 -V
Python 3.7.9
$ pip list
tensorflow 1.15.3
tensorflow-estimator 1.15.1
tensorlayer 2.2.3
回答3件
あなたの回答
tips
プレビュー