2017-06-27 3 views
0

の作成に失敗しました、エラーは次のとおりです。ここでTensorflow:私は自分のコードを実行すると、私はエラーを取得するセッション

tensorflow.python.framework.errors_impl.InternalError: Failed to create session.

は私のコードです:

# -*- coding: utf-8 -*- 
import ... 
import ... 

checkpoint='/home/vrview/tensorflow/example/char/data/model/' 
MODEL_SAVE_PATH = "/home/vrview/tensorflow/example/char/data/model/" 

def getAllImages(folder): 
    assert os.path.exists(folder) 
    assert os.path.isdir(folder) 
    imageList = os.listdir(folder) 
    imageList = [os.path.join(folder,item) for item in imageList ] 
    num=len(imageList) 
    return imageList,num 

def get_labei(): 
    img_dir, num = getAllImages(r"/home/vrview/tensorflow/example/char/data/model/file/") 
    for i in range(num): 
     image = Image.open(img_dir[i]) 
     image = image.resize([56, 56]) 
     image = np.array(image) 
     image_array = image 

     with tf.Graph().as_default(): 
      image = tf.cast(image_array, tf.float32) 
      image_1 = tf.image.per_image_standardization(image) 
      image_2 = tf.reshape(image_1, [1, 56, 56, 3]) 

      logit = color_inference.inference(image_2) 
      y = tf.nn.softmax(logit) 
      x = tf.placeholder(tf.float32, shape=[56, 56, 3]) 

      saver = tf.train.Saver() 
      with tf.Session() as sess: 
       ckpt = tf.train.get_checkpoint_state(MODEL_SAVE_PATH) 
       if ckpt and ckpt.model_checkpoint_path: 
        global_step = ckpt.model_checkpoint_path.split('/')[-1].split('-')[-1] 
        saver.restore(sess, ckpt.model_checkpoint_path) 
        print('Loading success, global_step is %s' % global_step) 
        prediction = sess.run(y) 
        max_index = np.argmax(prediction) 
       else: 
        print('No checkpoint file found') 

     path='/home/vrview/tensorflow/example/char/data/move_file/'+str(max_index) 
     isExists = os.path.exists(path) 
     if not isExists : 
      os.makedirs(path) 
     shutil.copyfile(img_dir[i], path) 

def main(argv=None): 
    get_labei() 

if __name__ == '__main__': 
    tf.app.run() 

そして、ここでは私のエラーです:

Traceback (most recent call last): 
    File "/home/vrview/tensorflow/example/char/data/model/color_class_2.py", line 61, in <module> 
    tf.app.run() 
    File "/home/vrview/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 44, in run 
    _sys.exit(main(_sys.argv[:1] + flags_passthrough)) 
    File "/home/vrview/tensorflow/example/char/data/model/color_class_2.py", line 58, in main 
    get_labei() 
    File "/home/vrview/tensorflow/example/char/data/model/color_class_2.py", line 40, in get_labei 
    with tf.Session() as sess: 
    File "/home/vrview/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 1187, in __init__ 
    super(Session, self).__init__(target, graph, config=config) 
    File "/home/vrview/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 552, in __init__ 
    self._session = tf_session.TF_NewDeprecatedSession(opts, status) 
    File "/usr/lib/python2.7/contextlib.py", line 24, in __exit__ 
    self.gen.next() 
    File "/home/vrview/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/framework/errors_impl.py", line 469, in raise_exception_on_not_ok_status 
    pywrap_tensorflow.TF_GetCode(status)) 
tensorflow.python.framework.errors_impl.InternalError: Failed to create session. 

私はいつもこのエラーが発生しますが、原因とその解決方法はわかりません。ありがとうございました。

+0

グラフの変数を初期化していません。 tf.Session()を 'sess'として' 'init_op = tf.global_variables_initializer()'の前にこの行を追加してください。そして 'sess:' sess: ' – Nain

答えて

0

GPUメモリ不足の可能性がありますか?試してみてください

export CUDA_VISIBLE_DEVICES='' 

また、使用しているプラ​​ットフォーム(オペレーティングシステム、アーキテクチャ)の詳細をご記入ください。あなたのTensorFlowバージョンも含めてください。

Pythonコンソールから簡単なセッションを作成できましたか?このような何か:

import tensorflow as tf 
hello = tf.constant('hi,tensorflow') 
sess = tf.Session() 
+0

で' tf.Session()の後ろに 'sess.run(init_op)'を追加してください。コンピュータを再起動してこの問題は解決しますが、理由はわかりません... –

+0

おそらくメモリの問題です。再起動すると、メモリ上のロックがクリアされ、クリアされます。 – JCooke

+0

エクスポート後、CUDA_VISIBLE_DEVICES = ''が使用されます.GPUアクセラレーションは現在使用されていません。また、サーバー上で作業する場合、どうすれば処理できますか?私はサーバーを再起動できません。 –

1

あなたのtensorflowは、GPUを使用することはできません

export CUDA_VISIBLE_DEVICES='' 

を実行した後。 CPUのみを使用してモデルのトレーニングを開始することがあります。

より良い解決策を見つけることができますhere。これは再起動を必要とせず、サーバーに適用することができます。

関連する問題