2017-07-31 206 views
0

以下代碼將掛起(只有一個CTRLz讓我出去)。當調用sess.run()時,Tensorflow掛起

import tensorflow as tf 
import cifar10 # from https://github.com/tensorflow/models/tree/master/tutorials/image/cifar10 (both cifar10.py & cifar10_input.py) 

def main(): 
    print 'TensorFlow version: ',tf.__version__ 

    with tf.Session() as sess: 

    with tf.device('/cpu:0'): 
     images, labels = cifar10.distorted_inputs() 

    input = tf.constant([[[1, 2, 3], [5, 5, 5]], [[4, 5, 6], [7, 7, 7]], [[7, 8, 9], [9, 9, 9]]]) 

    one=input[0] 
    print "X1 ",type(input), one 
    oneval = sess.run(one) 
    print "X2 ",type(one), one, type(oneval), oneval 

    two=images[0] 
    print "Y1 ",type(images), two 
    twoval = sess.run(two) 
    print "Y2 ",type(two), two, type(twoval), twoval 

main() 

我得到下面的輸出(與Python 2.7.5):

[[email protected] demo]$ python demo.py 
TensorFlow version: 1.2.1 
2017-07-31 16:06:45.503157: W tensorflow/core/platform/cpu_feature_guard.cc:45] >The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations. 
2017-07-31 16:06:45.503182: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations. 
2017-07-31 16:06:45.503187: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations. 
Filling queue with 20000 CIFAR images before starting to train. This will take a few minutes. 
X1 class 'tensorflow.python.framework.ops.Tensor'> Tensor("strided_slice:0", shape=(2, 3), dtype=int32) 
X2 class 'tensorflow.python.framework.ops.Tensor'> Tensor("strided_slice:0", shape=(2, 3), dtype=int32) <type 'numpy.ndarray'> [[1 2 3] [5 5 5]] 
Y1 class 'tensorflow.python.framework.ops.Tensor'> Tensor("strided_slice_1:0", shape=(24, 24, 3), dtype=float32) 
^Z 

任何人有任何建議(或解決方案)?

如果有人對背景感興趣,我的最終目標是將由distorted_inputs()返回的張量轉換爲一組JSON對象。因此,天真的計劃是迭代圖像的每個元素並提取值。

+0

有多久你離開它?我認爲這可能只是需要一段時間來加載圖像。你在CPU或GPU上運行它嗎? – finbarr

+0

現在已經運行了5分鐘。頂部顯示沒有活動。 strace顯示FUTEX_WAIT_PRIVATE。當我運行真正的程序(cifar10_train.py)時,它立即開始運行批處理,所以我不會期待延遲。 –

+0

這些都在CPU上(據我所知) - 運行在無法訪問GPU的虛擬機上。我認爲TensorFlow知道沒有GPU。 –

回答

相關問題