Found a workaround by adding keras.applications.mobilenet_v2.preprocess_input() as a layer in between an input layer and the premade model, like so:

input = keras.layers.Input([224, 224, 3])

pre = keras.applications.mobilenet_v2.preprocess_input(input)

net = keras.applications.MobileNetV2(
    input_tensor = pre,
    alpha=1.0,
    include_top=True,
    weights=None,
    classes=3,
    classifier_activation="softmax",
    name=None,
)
model = keras.Model(inputs=input, outputs=net.output)

Technically a different function than in the original question, but ultimately they both end up calling keras\src\applications\imagenet_utils.py and produce the same error when they do, so this should hopefully work for all preprocess_input functions that end up calling this.

Answer from Lentemern on Stack Overflow
🌐
GitHub
github.com › google › automl › issues › 893
AttributeError: 'PrefetchDataset' object has no attribute 'shape' · Issue #893 · google/automl
December 1, 2020 - Hi I have a problem when I tried to run "main.py".(7. Eval on COCO 2017 val or test-dev.) It seems that x has no attribute of "shape". Error is follows, please could you help me to solve this error. export MODEL=efficientdet-d0 export CK...
Author   takusaitoh
🌐
Stack Overflow
stackoverflow.com › questions › 70773884 › attributeerror-prefetchdataset-object-has-no-attribute-shape-when-using-tra
tensorflow2.0 - AttributeError: 'PrefetchDataset' object has no attribute 'shape' when using train_on_batch with tf.data.dataset - Stack Overflow
January 19, 2022 - Cannot batch tensors with different shapes in component 0 with tf.data.Dataset · 2 · tf.data.Dataset: The `batch_size` argument must not be specified for the given input type · 1 · PrefetchDataset' object has no attribute 'ndim' 1 · ValueError: Value tf.Tensor..
Discussions

python - '_PrefetchDataset' object has no attribute 'shape' when calling resnet_v2.preprocess_input() - Stack Overflow
I keep running into this error when trying to preprocess my datasets: AttributeError: '_PrefetchDataset' object has no attribute 'shape'. Did you mean: 'save'? I'm currently using ResNet, but I'v... More on stackoverflow.com
🌐 stackoverflow.com
keras - Tensorflow v1 Dataset API AttributeError with ndim - Data Science Stack Exchange
I'd like to make pipeline for optimizing Gpu and Cpu. Dataset It's about 10000 datapoint and 4 description variables for the regression problem. df = pd.read_csv("dataset") X_train, X_test, More on datascience.stackexchange.com
🌐 datascience.stackexchange.com
Dataset object has no attribute `to_tf_dataset`
I am following HuggingFace Course. I am at Fine-tuning a model. Link: Fine-tuning a pretrained model - Hugging Face Course I use tokenize_function and map as mentioned in the course to process data. # define a tokenize function def Tokenize_function(example): return tokenizer(example['sentence'], ... More on discuss.huggingface.co
🌐 discuss.huggingface.co
1
0
November 20, 2021
TypeError: 'PrefetchDataset' object is not subscriptable - General Discussion - Google AI Developers Forum
I have a custom dataset implemented using tfds, that returns image, label image is image of license plate shape (64,160,3) label is int from 0 to 36 representing character position in list of allowed characters for license plate (0…9,A…Z) shape (8) I am creating train batch / test batch ... More on discuss.ai.google.dev
🌐 discuss.ai.google.dev
0
April 11, 2023
🌐
GitHub
github.com › Bisonai › mobilenetv3-tensorflow › issues › 16
AttributeError: 'PrefetchDataset' object has no attribute 'output_shapes' · Issue #16 · Bisonai/mobilenetv3-tensorflow
AttributeError: 'PrefetchDataset' object has no attribute 'output_shapes'#16 · Copy link · Assignees · joshisr10 · opened · on Oct 7, 2020 · Issue body actions · Could you please advise on this error? I tried to resolve it through "tf.compat.v1.", but unsure of this new output_shapes error ----> line 34, in build_dataset dataset["channels"] = ds_train.output_shapes["image"][-1].value ·
🌐
Stack Exchange
datascience.stackexchange.com › questions › 46051 › tensorflow-v1-dataset-api-attributeerror-with-ndim
keras - Tensorflow v1 Dataset API AttributeError with ndim - Data Science Stack Exchange
AttributeError: 'PrefetchDataset' object has no attribute 'ndim' I saw some issues with this problem. But it didn't work for me. Software version: Keras:2.2.4 Tensorflow:1.12.0 · keras · tensorflow · pipelines · Share · Improve this question · Follow · edited Nov 30, 2020 at 13:28 ·
🌐
Kaggle
kaggle.com › code › mukulkirti › 8-tensorflow-pipline
Checking your browser - reCAPTCHA
Click here if you are not automatically redirected after 5 seconds.
🌐
Google AI
discuss.ai.google.dev › tensorflow › general discussion
TypeError: 'PrefetchDataset' object is not subscriptable - General Discussion - Google AI Developers Forum
April 11, 2023 - I have a custom dataset implemented using tfds, that returns image, label image is image of license plate shape (64,160,3) label is int from 0 to 36 representing character position in list of allowed characters for license plate (0…9,A…Z) shape (8) I am creating train batch / test batch with size 8 ds_train_batch = ds_train.cache() ds_train_batch = ds_train_batch.batch(BatchSize) ds_train_batch = ds_train_batch.prefetch(tf.data.AUTOTUNE) ds_test_batch = ds_test.cache() ds_test_batch = ds_t...
Find elsewhere
🌐
Hugging Face
discuss.huggingface.co › 🤗datasets
Seeing AttributeError: 'Dataset' object has no attribute 'reshape' when using "dataset.get_nearest_examples" - 🤗Datasets - Hugging Face Forums
June 25, 2023 - Hello, I am trying to use Faiss indexing for an image similarity application. However, I am seeing an Attribute Error. Here’s the code that I am trying # Loading dataset dataset = load_dataset("imagefolder", data_dir="/data") # Pre processing images def transforms(examples): examples["image"] = [image.resize((384, 384)).convert("RGB") for image in examples["image"]] return examples # Applying the transform function to dataset dataset = dataset.map(transforms, batched=True, batch_size=...
🌐
Reddit
reddit.com › r/tensorflow › [help] error passing tfrecorddataset to keras
[Mature Content] r/tensorflow on Reddit: [Help] Error Passing TFRecordDataset to Keras
January 4, 2020 -

Greetings,

I have serialized and stored some data as TFRecords, and created datasets from these records using TFRecordDataset. I was under the impression that this can be passed directly to a Keras model for fitting, but I am receiving an error. If I attempt to batch the dataset, the error I get upon attempting to fit is AttributeError: 'BatchDataset' objecthas no attribute 'ndim.' If I attempt to shuffle the training dataset before fitting, I get AttributeError: 'ShuffleDataset' object has no attribute 'ndim.' If I do neither of these and just pass the dataset as-is, I get AttributeError: 'TFRecordDatasetV2' objecthas no attribute 'ndim.'

Seems like Keras is still expecting an array, which I don't quite understand. Am I missing something? In the TF documentation, they have an example where they pass a Dataset created from tensor slices, but not one created from TFRecords.

🌐
TensorFlow
tensorflow.org › jvm › prefetchdataset
PrefetchDataset | JVM | TensorFlow
Factory method to create a class wrapping a new PrefetchDataset operation. ... Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers ...
🌐
Reddit
reddit.com › r/tensorflow › getting tensorflow prefetchdataset through kesas textvectorization layer
[Mature Content] r/tensorflow on Reddit: Getting Tensorflow PrefetchDataset through Kesas TextVectorization layer
September 15, 2021 - I am on tf_nightly-2.7.0 and used tensorflow's "make_csv_dataset" to make dataset from a TSV file, but it seems the Tensorflow PrefetchDataset doesn't have shape information. I could have used Pandas dataframe but would like to try Tensorflow's dataset.
🌐
Blogger
gfyuki.blogspot.com › 2019 › 02 › tensorflow-dataset-api-ndim.html
Tensorflow Dataset API: ndim
February 22, 2019 - AttributeError: 'PrefetchDataset' object has no attribute 'ndim' I saw some issue for this problme, it's following. https://github.com/tensorflow/tensorflow/issues/20698 · But it didn't work for me. Software version: Keras:2.2.4 Tensorflow:1.12.0 · keras tensorflow ·
🌐
Nengo forum
forum.nengo.ai › deep learning
Questions about training the converted model with dynamic input pipeline in Nengo-dl - Deep Learning - Nengo forum
June 4, 2022 - When training my model with Nengo-dl, I used the tensorflow map function to preprocess my dataset. The code below basically shows how do I preprocess my dataset. ##"files" here just mean a tensor of filenames on disk def preprocess_dataset(files): files_ds = tf.data.Dataset.from_tensor_slices(files) output_ds = files_ds.map( map_func=first_preprocess_step, ) output_ds = output_ds.map( map_func=second_preprocess_step, ) return output_ds Since I got ma...
🌐
Stack Overflow
stackoverflow.com › questions › tagged › tensorflow-datasets
Newest 'tensorflow-datasets' Questions - Page 5 - Stack Overflow
October 24, 2022 - I was trying to install the module tensorflow_datasets: pip install tensorflow_datasets==4.6.0 I encountered the following error: × python setup.py egg_info did not run successfully. │ exit code: ... ... Getting AttributeError: '_NumpyIterator' object has no attribute 'shard' while executing below code.My dataset is having images and labels which I want to convert to tfrecords ds_train = tf.keras....