The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

191537 (6) [Avatar] Offline
#1
Hi ,

I am trying to run 5.1 listing on my local machine but I cannot do it.

I am getting the error as follows:

FailedPreconditionError Traceback (most recent call last) FailedPreconditionError: Attempting to use uninitialized value matching_filenames_18 [[Node: matching_filenames_18/read = IdentityT=DT_STRING, _class=["loc:@matching_filenames_18"], _device="/job:localhost/replica:0/task:0/cpu:0"]]

What am I missing please ?

Marcin
Yonatan Betzer (1) [Avatar] Offline
#2
Try this:

import tensorflow as tf
from os import listdir
from os.path import isfile, join

filenames = ["audio_dataset/" + f for f in listdir("audio_dataset") if isfile(join("audio_dataset", f)) and f.endswith('.wav')]

count_num_files = tf.size(filenames)
filename_queue = tf.train.string_input_producer(filenames)
reader = tf.WholeFileReader()
filename, file_contents = reader.read(filename_queue)
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    num_files = sess.run(count_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)

191537 (6) [Avatar] Offline
#3
It worked;
Thank you very much;
I also switched to 2.7 which could be an additional problem.

many thanks
Moheb (1) [Avatar] Offline
#4
use this initializer instead:

 
sess.run(tf.local_variables_initializer())
633056 (4) [Avatar] Offline
#5
Looks like quite a few of the functions used in this listing have been deprecated. I'm currently trying...

filenames = tf.train.match_filenames_once('C:\\Users\\Paul\\Music\\*.mp3')

count_num_files = tf.size(filenames)

#DEPRECATED( filename_queue = tf.train.string_input_producer(filenames) )
filename_queue = tf.data.Dataset.from_tensor_slices(filenames)

#DEPRECATED( reader = tf.WholeFileReader() )
reader = filename_queue.map(tf.read_file)

#DEPRECATED?( filename, file_contents = reader.read(filename_queue) )

with tf.Session() as sess:
    
    sess.run(tf.global_variables_initializer())

    #breaks counting files.
    num_files = sess.run(count_num_files)
    


Help, or a completed example, would be much appreciated.
633056 (4) [Avatar] Offline
#6
Figured it out using my finely honed two step debugging process (google -> click stackoverflow link)...

filenames = tf.train.match_filenames_once('C:\\Users\\Paul\\Music\\*.mp3')
count_num_files = tf.size(filenames)

filename_queue = tf.data.Dataset.from_tensor_slices(filenames)
reader = filename_queue.map(tf.read_file)

#filename, file_contents = reader.read(filename_queue)

with tf.Session() as sess:

    sess.run(tf.global_variables_initializer())
    sess.run(tf.local_variables_initializer())
    
    num_files = sess.run(count_num_files)
    print(num_files)
    
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord = coord)
    
    audio_file = sess.run(filenames)
    print(audio_file)


1. Looks like tf is deprecating data management outside of their tf.data.Dataset structures so be sure to look for that in future chapters.
2. tf.train.match_filenames_once(...) function initializes local variables. You have to initialize local variables using tf.local_variables_initializer()
3. tf.train.start_queue_runners is throwing a warning saying it will be removed soon.
4. Not sure how to get the equivalent of the reader.read functionality to work.
5. Make sure you take the for loop out with this code. I ended up printing to screen 412 file names 412 times...