मैं tensorflow में कुछ डेटा पढ़ने की कोशिश कर रहा हूं, और उसके बाद इसे अपने लेबल से मेल खाता हूं। मेरे सेटअप इस प्रकार है:गलत उदाहरण में मेरे उदाहरण और लेबल क्यों हैं?
- मैं अंग्रेज़ी अक्षरों की एक सरणी है,
"a", "b", "c", "d", "e", ...
- मेरे पास है "सिरिलिक" पत्र,
"a", "b", "w, "g", "d", ...
की एक सरणी, - मैं संख्या की एक सरणी है,
0, 1, 2, 3, 4, ...
मैं उदाहरणों की एक कतार बनाना चाहता हूं जिसमें पहले दो एरे के बीच जोड़े हैं, जैसे ["b", "b"], ["d", "g"], ["c", "w"], ...
। मैं उन जोड़ों के लिए इसी संख्या की कतार भी चाहता हूं, जो इस मामले में 1, 3, 2, ...
हालांकि, जब मैं इन कतारों को उत्पन्न करता हूं, तो मेरे उदाहरण और मेरी संख्याएं मेल नहीं खाती हैं - उदाहरण के लिए, ["b", "b"], ["d", "g"], ["c", "w"], ...
की कतार 5, 0, 2, ...
की एक लेबल कतार के साथ आता है।
इसका कारण क्या हो सकता है? परीक्षण के लिए, मैंने कतार/बैच पीढ़ी में सभी शफलिंग को अक्षम कर दिया है, लेकिन समस्या बनी हुई है।
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import tensorflow as tf
from constants import FLAGS
letters_data = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
cyrillic_letters_data = ["a", "b", "w", "g", "d", "e", "j", "v", "z", "i"]
numbers_data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
def inputs(batch_size):
# Get the letters and the labels
(letters, labels) = _inputs(batch_size=batch_size)
# Return the letters and the labels.
return letters, labels
def read_letter(pairs_and_overlap_queue):
# Read the letters, cyrillics, and numbers.
letter = pairs_and_overlap_queue[0]
cyrillic = pairs_and_overlap_queue[1]
number = pairs_and_overlap_queue[2]
# Do something with them
# (doesn't matter what)
letter = tf.substr(letter, 0, 1)
cyrillic = tf.substr(cyrillic, 0, 1)
number = tf.add(number, tf.constant(0))
# Return them
return letter, cyrillic, number
def _inputs(batch_size):
# Get the input data
letters = letters_data
cyrillics = cyrillic_letters_data
numbers = numbers_data
# Create a queue containing the letters,
# the cyrillics, and the numbers
pairs_and_overlap_queue = tf.train.slice_input_producer([letters, cyrillics, numbers],
capacity=100000,
shuffle=False)
# Perform some operations on each of those
letter, cyrillic, number = read_letter(pairs_and_overlap_queue)
# Combine the letters and cyrillics into one example
combined_example = tf.stack([letter, cyrillic])
# Ensure that the random shuffling has good mixing properties.
min_fraction_of_examples_in_queue = 0.4
min_queue_examples = int(FLAGS.NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN *
min_fraction_of_examples_in_queue)
# Generate an example and label batch, and return it.
return _generate_image_and_label_batch(example=combined_example, label=number,
min_queue_examples=min_queue_examples,
batch_size=batch_size,
shuffle=False)
def _generate_image_and_label_batch(example, label, min_queue_examples,
batch_size, shuffle):
# Create a queue that shuffles the examples, and then
# read 'batch_size' examples + labels from the example queue.
num_preprocess_threads = FLAGS.NUM_THREADS
if shuffle:
examples, label_batch = tf.train.shuffle_batch(
[example, label],
batch_size=batch_size,
num_threads=num_preprocess_threads,
capacity=min_queue_examples + 6 * batch_size,
min_after_dequeue=min_queue_examples)
else:
print("Not shuffling!")
examples, label_batch = tf.train.batch(
[example, label],
batch_size=batch_size,
num_threads=num_preprocess_threads,
capacity=min_queue_examples + 6 * batch_size)
# Return the examples and the labels batches.
return examples, tf.reshape(label_batch, [batch_size])
lcs, nums = inputs(batch_size=3)
with tf.Session() as sess:
# Start populating the filename queue.
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord, sess=sess)
for i in xrange(0, 5):
my_lcs = lcs.eval()
my_nums = nums.eval()
print(str(my_lcs) + " --> " + str(my_nums))
धन्यवाद आपकी मदद के लिए एक बहुत:
यहाँ मेरी कोड है!
उह, बहुत बहुत धन्यवाद। मुझे वास्तव में यह ढूंढने में सक्षम होना चाहिए था, लेकिन मुझे यकीन था कि त्रुटि मेरी बैच पीढ़ी में थी। धन्यवाद! – 416E64726577
अच्छी जांच! –