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

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

新規登録して質問してみよう
ただいま回答率
85.48%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

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

Q&A

解決済

1回答

7058閲覧

tensorflowチュートリアルプログラム(cifar10)が動きません…

aika_y

総合スコア8

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

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

0グッド

0クリップ

投稿2017/05/25 06:49

###前提・実現したいこと
初めまして。
独学で画像認識を勉強している者です。
tensorflowのチュートリアルプログラム(cifar10)を実行しようとしたのですが、
エラーが発生して動きません。
どうか、ご教授願います。

###発生している問題・エラーメッセージ

Traceback(most recent call last): File "cifar10_train.py",line 47, in <module> from tensorflow.models.image.cifar10 import cifar10 ImportError: No module named 'tensorflow.models'

###該当のソースコード

python

1# Copyright 2015 The TensorFlow Authors. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================== 15 16"""A binary to train CIFAR-10 using a single GPU. 17 18Accuracy: 19cifar10_train.py achieves ~86% accuracy after 100K steps (256 epochs of 20data) as judged by cifar10_eval.py. 21 22Speed: With batch_size 128. 23 24System | Step Time (sec/batch) | Accuracy 25------------------------------------------------------------------ 261 Tesla K20m | 0.35-0.60 | ~86% at 60K steps (5 hours) 271 Tesla K40m | 0.25-0.35 | ~86% at 100K steps (4 hours) 28 29Usage: 30Please see the tutorial and website for how to download the CIFAR-10 31data set, compile the program and train the model. 32 33http://tensorflow.org/tutorials/deep_cnn/ 34""" 35from __future__ import absolute_import 36from __future__ import division 37from __future__ import print_function 38 39from datetime import datetime 40 41import os.path 42import time 43 44import numpy as np 45from six.moves import xrange # pylint: disable=redefined-builtin 46import tensorflow as tf 47 48from tensorflow.models.image.cifar10 import cifar10 49 50FLAGS = tf.app.flags.FLAGS 51 52tf.app.flags.DEFINE_string('train_dir', '/tmp/cifar10_train', 53 """Directory where to write event logs """ 54 """and checkpoint.""") 55tf.app.flags.DEFINE_integer('max_steps', 1000000, 56 """Number of batches to run.""") 57tf.app.flags.DEFINE_boolean('log_device_placement', False, 58 """Whether to log device placement.""") 59 60 61def train(): 62 """Train CIFAR-10 for a number of steps.""" 63 with tf.Graph().as_default(): 64 global_step = tf.Variable(0, trainable=False) 65 66 # Get images and labels for CIFAR-10. 67 images, labels = cifar10.distorted_inputs() 68 69 # Build a Graph that computes the logits predictions from the 70 # inference model. 71 logits = cifar10.inference(images) 72 73 # Calculate loss. 74 loss = cifar10.loss(logits, labels) 75 76 # Build a Graph that trains the model with one batch of examples and 77 # updates the model parameters. 78 train_op = cifar10.train(loss, global_step) 79 80 # Create a saver. 81 saver = tf.train.Saver(tf.all_variables()) 82 83 # Build the summary operation based on the TF collection of Summaries. 84 summary_op = tf.merge_all_summaries() 85 86 # Build an initialization operation to run below. 87 init = tf.initialize_all_variables() 88 89 # Start running operations on the Graph. 90 sess = tf.Session(config=tf.ConfigProto( 91 log_device_placement=FLAGS.log_device_placement)) 92 sess.run(init) 93 94 # Start the queue runners. 95 tf.train.start_queue_runners(sess=sess) 96 97 summary_writer = tf.train.SummaryWriter(FLAGS.train_dir, sess.graph) 98 99 for step in xrange(FLAGS.max_steps): 100 start_time = time.time() 101 _, loss_value = sess.run([train_op, loss]) 102 duration = time.time() - start_time 103 104 assert not np.isnan(loss_value), 'Model diverged with loss = NaN' 105 106 if step % 10 == 0: 107 num_examples_per_step = FLAGS.batch_size 108 examples_per_sec = num_examples_per_step / duration 109 sec_per_batch = float(duration) 110 111 format_str = ('%s: step %d, loss = %.2f (%.1f examples/sec; %.3f ' 112 'sec/batch)') 113 print (format_str % (datetime.now(), step, loss_value, 114 examples_per_sec, sec_per_batch)) 115 116 if step % 100 == 0: 117 summary_str = sess.run(summary_op) 118 summary_writer.add_summary(summary_str, step) 119 120 # Save the model checkpoint periodically. 121 if step % 1000 == 0 or (step + 1) == FLAGS.max_steps: 122 checkpoint_path = os.path.join(FLAGS.train_dir, 'model.ckpt') 123 saver.save(sess, checkpoint_path, global_step=step) 124 125 126def main(argv=None): # pylint: disable=unused-argument 127 cifar10.maybe_download_and_extract() 128 if tf.gfile.Exists(FLAGS.train_dir): 129 tf.gfile.DeleteRecursively(FLAGS.train_dir) 130 tf.gfile.MakeDirs(FLAGS.train_dir) 131 train() 132 133 134if __name__ == '__main__': 135 tf.app.run() 136 137

###試したこと
import sys やシェルでexport PYTHONPATH =""でパスを指定してみても駄目でした。

###補足情報(言語/FW/ツール等のバージョンなど)
言語 :python3.5
ツール:tensorflow1.1.0
OS :ubuntu16.04

使用プログラム
https://github.com/tensorflow/tensorflow/tree/r0.10

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

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

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

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

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

guest

回答1

0

ベストアンサー

動作未検証ですが、tensorflow1.x系の場合、以下を利用してみてどうでしょうか?
models/tutorials/image/cifar10/cifar10_train.py

投稿2017/05/25 07:14

can110

総合スコア38266

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

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

aika_y

2017/05/25 07:52

modelをすべて落としてcifar10_train.pyを実行してみたところ、きちんと実行ができました。 本当にありがとうございます!
can110

2017/05/25 07:56

githubのmaster/tensorflowから追っていくと、古いr0.10に飛んじゃうようですね。 tensorflowは変化が激しいのでリンク更新されていないのかもしれません。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問