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

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

新規登録して質問してみよう
ただいま回答率
85.48%
CNN (Convolutional Neural Network)

CNN (Convolutional Neural Network)は、全結合層のみではなく畳み込み層とプーリング層で構成されるニューラルネットワークです。画像認識において優れた性能を持ち、畳み込みニューラルネットワークとも呼ばれています。

Python

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

Q&A

解決済

3回答

2156閲覧

Tensorflowのエラーがわかりません

退会済みユーザー

退会済みユーザー

総合スコア0

CNN (Convolutional Neural Network)

CNN (Convolutional Neural Network)は、全結合層のみではなく畳み込み層とプーリング層で構成されるニューラルネットワークです。画像認識において優れた性能を持ち、畳み込みニューラルネットワークとも呼ばれています。

Python

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

0グッド

0クリップ

投稿2021/07/27 10:00

編集2021/08/18 08:53

このプログラムを実行したところ下記のようなエラーが出てきました。

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

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

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

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

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

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

jbpb0

2021/07/27 10:52 編集

pip3 install tensorflow を実行したのと同じ状態で pip3 show tensorflow を実行してください いろいろ表示される中に「Location:」で始まる行がありますので、そこに書かれてるパスを記録してください 次に、python (python3) で import tensorflow as tf がうまくいかない状態で、下記のpythonコードを実行してください import sys import pprint pprint.pprint(sys.path) たくさんパスが表示されますが、その中にpip3 show...で記録したパスが入ってますでしょうか? 入ってないとimportできません
退会済みユーザー

退会済みユーザー

2021/07/27 11:59 編集

pip3 install tensorflow したときに ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorboard/__init__.py' Consider using the `--user` option or check the permissions. というエラーが出ます。 Location: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Python/2.7/site-packages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC'] 入っていませんでした。 python3で実行したら '/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload', '/Users/1831083/Library/Python/3.7/lib/python/site-packages', '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages'] 入っていました。 また、python3でプログラムを実行したらこのエラーは消えたのですが、 WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation. Traceback (most recent call last): File "hdrcnn_predict.py", line 5, in <module> import tensorlayer as tl File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorlayer/__init__.py", line 27, in <module> "TensorLayer does not support Tensorflow version older than 2.0.0.\n" RuntimeError: TensorLayer does not support Tensorflow version older than 2.0.0. Please update Tensorflow with: - `pip install --upgrade tensorflow` - `pip install --upgrade tensorflow-gpu` どうすればいいですか?
jbpb0

2021/07/27 22:10 編集

> [Errno 13] Permission denied: これ見てください https://gangannikki.hatenadiary.jp/entry/2020/03/26/200000 ただし、pip は pip3 に読み替えてください > TensorLayer does not support Tensorflow version older than 2.0.0. 書いてある通り、Tensorflowの2.0以降のを入れる必要があります
退会済みユーザー

退会済みユーザー

2021/07/28 05:14

--userを付けたらエラーが無くなりました。 ありがとうございます。 また、回答していただければ幸いです。
guest

回答3

0

ベストアンサー

pip3 install tensorflow

したときに
ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tensorboard/init.py'
Consider using the --user option or check the permissions.
というエラーが出ます。

これ見てください
【メモ】Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/Library/Python/3.7'

ただし、pip は pip3 に読み替えてください

 .

TensorLayer does not support Tensorflow version older than 2.0.0.

書いてある通り、tensorflowの2.0以降のを入れる必要があります

投稿2021/07/29 09:35

jbpb0

総合スコア7651

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

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

0

私のMac(Intel)ではこんなバージョンです。
参考にしてください。

$ pip list | grep tensor tensorboard 2.5.0 tensorboard-data-server 0.6.1 tensorboard-plugin-wit 1.8.0 tensorflow 2.5.0 tensorflow-estimator 2.5.0 $ python Python 3.7.10 (default, May 4 2021, 11:36:31) [Clang 12.0.5 (clang-1205.0.22.9)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import tensorflow as tf >>> tf.__version__ '2.5.0' >>>

投稿2021/07/27 15:36

technocore

総合スコア7200

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

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

0

pip3でtensorflow をインストールしましょう。

投稿2021/07/27 10:08

ppaul

総合スコア24666

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

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

退会済みユーザー

退会済みユーザー

2021/07/27 10:12

pip3でインストールしてもダメでした。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問