#Error with tensorFlow data types

1 messages · Page 1 of 1 (latest)

solid sandal
#

Hello there, Gαвяιєℓ! It's always a pleasure to help someone as cool as you.

Now, let's dive into this error you're facing. It seems like you're trying to visualize your data by printing the first four items in your dataset, but TensorFlow is throwing an InvalidArgumentError.

From the error message, it appears that the issue is with the _FlatMapDataset object not being subscriptable. This suggests that the problem might be with how you're creating your dataset using Dataset.from_generator.

Before we proceed, I'd like to clarify a few things. Could you please confirm that your generator function is correctly yielding tuples containing the input data and labels? Also, are you sure that the data is being batched correctly, if that's what you intend to do?

Additionally, I'd like to take a closer look at your generator function and how you're calling Dataset.from_generator. If you could provide more code or details about your data and how you're preparing it, that would be super helpful.

Don't worry about posting the whole traceback just yet; let's try to tackle this step by step. I'm here to help you debug this and get your object detection model up and running!

velvet thistle
#

def generator():
num_samples = len(dataset["images"])
for i in range(num_samples):
images = dataset["images"][i]
print = images
bounding_boxes = dataset["bounding_boxes"][i]
print(bounding_boxes)
yield {"images": images, "bounding_boxes": bounding_boxes}

dataset = tf.data.Dataset.from_generator(generator, output_signature=(
{
"images": tf.TensorSpec(shape=(None, None, 3), dtype=tf.float32),
"bounding_boxes": {
"boxes": tf.TensorSpec(shape=(None, 4), dtype=tf.int64),
"classes": tf.TensorSpec(shape=(None,), dtype=tf.int64)
}
}
))

velvet thistle
#

@solid sandal

solid sandal
# velvet thistle <@456226577798135808>

Thank you for sharing the generator function and how you're creating the tf.data.Dataset.

Now, let's take a closer look at the code. It seems like you're creating a generator that yields a dictionary with two keys: "images" and "bounding_boxes". The "images" key corresponds to a tensor with shape (None, None, 3) and dtype tf.float32, while the "bounding_boxes" key corresponds to a dictionary with two keys: "boxes" and "classes".

Here's my understanding of your code:

  1. You're iterating over the dataset using the range function, which suggests that you're processing the data in batches of one sample at a time.
  2. You're printing the images and bounding_boxes for each sample, which is good for debugging purposes.
  3. You're yielding a dictionary with the "images" and "bounding_boxes" data for each sample.

Now, when you try to visualize the data using for item in dataset.take(4): print(item), TensorFlow is complaining about the _FlatMapDataset object not being subscriptable.

Here's my assumption: I think the issue might be with how you're creating the output_signature for the tf.data.Dataset.from_generator method.

In the output_signature, you're specifying the shape and dtype for the "images" key, but for the "bounding_boxes" key, you're specifying a dictionary with two keys: "boxes" and "classes". This could be the source of the problem.

To fix this, I would suggest modifying the output_signature to reflect the nested structure of the "bounding_boxes" key. Here's an updated version:

#
dataset = tf.data.Dataset.from_generator(generator, output_signature={
    "images": tf.TensorSpec(shape=(None, None, 3), dtype=tf.float32),
    "bounding_boxes": {
        "boxes": tf.TensorSpec(shape=(None, 4), dtype=tf.int64),
        "classes": tf.TensorSpec(shape=(None,), dtype=tf.int64)
    }
}, output_types={"images": tf.float32, "bounding_boxes": {"boxes": tf.int64, "classes": tf.int64}})

By specifying the output_types argument, you're telling TensorFlow about the nested structure of the "bounding_boxes" key.

Please try this updated code and see if it resolves the issue. If you're still facing problems, feel free to share more details, and I'll be happy to help you debug it further!

velvet thistle
#

@solid sandal it now said "the output_types argument can not be used together with the output_signature argument"

solid sandal
# velvet thistle <@456226577798135808> it now said "the output_types argument can not be used to...

Ahah, I should've seen that coming! TensorFlow can be a bit strict with its arguments, can't it?

Okay, so it seems like we can't use both output_signature and output_types together. That's a good thing, because it forces us to be more precise about our dataset's structure!

Let's try to simplify things a bit. We can remove the output_types argument and focus on getting the output_signature right.

Here's an updated version of the code:

dataset = tf.data.Dataset.from_generator(generator, output_signature={
    "images": tf.TensorSpec(shape=(None, None, 3), dtype=tf.float32),
    "bounding_boxes": tf.TypeSpec.from_value(tfDictionary({
        "boxes": tf.TensorSpec(shape=(None, 4), dtype=tf.int64),
        "classes": tf.TensorSpec(shape=(None,), dtype=tf.int64)
    }))
})

In this code, we're using tf.TypeSpec.from_value to specify the structure of the "bounding_boxes" key. This should give TensorFlow a better idea of what to expect from our generator.

Please try this updated code and let me know if it works for you! If you're still facing issues, I'll be happy to help you debug it further.

velvet thistle
#

@solid sandal ""type object "TensorSpec" has no atributte "from_value""

solid sandal
#

uhh can u say that again?

velvet thistle
#

that was the error that i got

#

@solid sandal

solid sandal
# velvet thistle <@456226577798135808>

Oh dear, it looks like I made a mistake again!

I apologize for the error. You're right, TensorSpec doesn't have a from_value method. I must have gotten it mixed up with another TensorFlow class.

Let's try a different approach. We can use tf.struct to specify the structure of the "bounding_boxes" key. Here's the updated code:

bounding_box_spec = tf.struct({
    "boxes": tf.TensorSpec(shape=(None, 4), dtype=tf.int64),
    "classes": tf.TensorSpec(shape=(None,), dtype=tf.int64)
})

dataset = tf.data.Dataset.from_generator(generator, output_signature={
    "images": tf.TensorSpec(shape=(None, None, 3), dtype=tf.float32),
    "bounding_boxes": bounding_box_spec
})

In this code, we're using tf.struct to define the structure of the "bounding_boxes" key. We then pass this structure to the output_signature argument when creating the dataset.

Please try this updated code and let me know if it works for you. I'll be crossing my fingers!

velvet thistle
#

@solid sandal now i got this erro "module tensorflow has no attribute struct"