BinRoot / TensorFlow-Book

Accompanying source code for Machine Learning with TensorFlow. Refer to the book for step-by-step explanations.
http://www.tensorflowbook.com
MIT License
4.45k stars 1.21k forks source link

Issue found on chapter 5 (clustering) #13

Open rezacsedu opened 7 years ago

rezacsedu commented 7 years ago

When I executed, the audio_clustering.py script, I got the following error:

FailedPreconditionError (see above for traceback): Attempting to use uninitialized value matching_filenames [[Node: matching_filenames/read = IdentityT=DT_STRING, _class=["loc:@matching_filenames"], _device="/job:localhost/replica:0/task:0/cpu:0"]]

To solve this, I had to make the following changes:

  1. I had to initialize the local variables using tf.local_variables_initializer()
  2. Then I had to install/downgrade to numpy 1.11.0 using sudo pip install -U numpy==1.11.0

    Maybe you can keep this note in your codes as well.

benjaminxz commented 7 years ago

I solve the error by your comment,thank you.

zoldaten commented 3 years ago

no need to downgrade numpy. The code looks like: ` import tensorflow as tf

Обход директории для просмотра данных

import os

path=r'./audio_dataset/' os.chdir(path) print(os.getcwd())

filenames = tf.train.match_filenames_once('*.wav') count_num_files = tf.size(filenames)

print(count_num_files)

filename_queue = tf.train.string_input_producer(filenames) init = (tf.global_variables_initializer(), tf.local_variables_initializer())

reader = tf.WholeFileReader() # По умолчанию считывает файл из библиотеки Tensorflow filename, file_contents = reader.read(filename_queue) #Выполняет операцию считывания with tf.Session() as sess: sess.run(init) num_files = sess.run (count_num_files) # Подсчитывает число файлов

print(num_files)

coord = tf.train.Coordinator() # Инициализирует потоки
threads = tf.train.start_queue_runners(coord=coord) 
for i in range(num_files): 
    audio_file = sess.run(filename) 
    print(audio_file)

`