I am new to tf and I have a problem where I am trying to process some files. Here is a excerpt of code.
xlabel_to_files_list_map['dog_bark'] # subset of data with two files
# result
['gs://some_bucket/some_dir/data/dog_bark/100652.mp3', 'gs://some_bucket/some_dir/dog_bark/100795.mp3']
Here is where I am simply trying to get these strings to be processed by a simple graph:
file_to_process = tf.placeholder(tf.string)
audio_binary_remote = tf.gfile.Open(file_to_process, 'rb').read()
waveform = tf.contrib.ffmpeg.decode_audio(audio_binary_remote, file_format='mp3', samples_per_second=44100, channel_count=2)
with tf.Session() as sess:
result = sess.run(waveform, feed_dict={
file_to_process: xlabel_to_files_list_map['dog_bark']
})
#print (result)
This results in
TypeError: Expected binary or unicode string, got <tf.Tensor 'Placeholder_9:0' shape=<unknown> dtype=string>
FWIW, this works
a_string = tf.placeholder(tf.string)
z = a_string
with tf.Session() as sess:
result = sess.run(z, feed_dict={a_string: ['one', 'two', 'three']})
print(result)
This results in
['one' 'two' 'three']
The simple example which works is of a list of strings. The more complex example which uses a hash map value part which is a list of strings. I'm not sure why it doesn't work similar to the second example.
Another Approach
I tried to do this another way. This time I tried to build a list of results and then process the list. This also failed. It did not produce an error. It simply gave blank results.
waveform_tensor_list = []
for a_file in dir_to_selected_files_list_map['gs://some_bucket/some_dir/dog_bark/']:
#print (a_file)
waveform = tf.contrib.ffmpeg.decode_audio(a_file, file_format='mp3', samples_per_second=44100, channel_count=2)
waveform_tensor_list.append(waveform)
The output from this cell looks wrong immediately but in the proper form:
waveform_tensor_list
resulting in:
[<tf.Tensor 'DecodeAudioV2_7:0' shape=(?, 2) dtype=float32>,
<tf.Tensor 'DecodeAudioV2_8:0' shape=(?, 2) dtype=float32>,
stuff deleted,
<tf.Tensor 'DecodeAudioV2_22:0' shape=(?, 2) dtype=float32>,
<tf.Tensor 'DecodeAudioV2_23:0' shape=(?, 2) dtype=float32>]
Then to evaluate the graph, this:
with tf.Session() as sess:
result = sess.run(waveform_tensor_list)
print (result)
Where the output from this cell is:
[array([], shape=(0, 0), dtype=float32), array([], shape=(0, 0), dtype=float32), array([], shape=(0, 0), dtype=float32), array([], shape=(0, 0), dtype=float32), array([], shape=(0, 0), dtype=float32), array([], shape=(0, 0), dtype=float32), array([], shape=(0, 0), dtype=float32), array([], shape=(0, 0), dtype=float32), array([], shape=(0, 0), dtype=float32), array([], shape=(0, 0), dtype=float32), array([], shape=(0, 0), dtype=float32), array([], shape=(0, 0), dtype=float32), array([], shape=(0, 0), dtype=float32), array([], shape=(0, 0), dtype=float32), array([], shape=(0, 0), dtype=float32), array([], shape=(0, 0), dtype=float32), array([], shape=(0, 0), dtype=float32)]