42,134 questions
1
vote
1
answer
49
views
ValueError: Can't convert non-rectangular Python sequence to Tensor in text-classification problem
I am building a text classification system which requires a large preprocessing and training script. The script reads variable-length token sequences and attempts to build a tf.data.Dataset using ...
3
votes
1
answer
43
views
How to fix ValueError: Only instances of keras.Layer can be added to a Sequential model when adding tensorflow_hub.KerasLayer?
I am learning TensorFlow and transfer learning, and I am trying to add a TensorFlow Hub feature extractor to a Keras Sequential model. But I get this error:
ValueError: Only instances of keras.Layer ...
0
votes
1
answer
56
views
TensorFlow throws cuDNN/cuBLAS/cuFFT and MessageFactory errors on Kaggle
I am working on a Kaggle notebook where I am trying to import TensorFlow/Keras to build a simple neural network for tabular data.
However, even with Accelerator = None (CPU only), TensorFlow fails ...
3
votes
1
answer
62
views
Unable to import_model .h5 in an attemp to try classification because of "BatchNormalization could not be deserialized properly"
I've got a very small python script using a Model.h5 which should be loaded in order to classify some pictures.
Here's my python script :
import tensorflow as tf
from os import walk
from keras.models ...
0
votes
1
answer
58
views
Tensor Flow -No attribute Contribute
I am trying to duplicate the code found here which says tested with TensorFlow 1.6.
I am using TF version 2.20.0 and really don't want to downgrade to 1.6 so I tried:
import tensorflow.compat.v1 as tf ...
0
votes
1
answer
103
views
multi output forcast shape prob. with keras.preprocessing.timeseries_dataset_from_array
The model was fuctioinnal with only one output, now I try to use multi output forcasting one timestep, but got this error:
Epoch 1/10
2025-11-04 16:20:09.341769: W tensorflow/core/framework/op_kernel....
2
votes
1
answer
110
views
Will tf.keras.Sequential containing multiple custom layers be correctly fully serializable and deserializable in my case?
I am implementing a U-Net variant in TensorFlow/Keras with custom layers. In one of my layers custom layers UPDoubleConv, I have a Sequential self.blocks containing a repeated pattern of UpSampling2D ...
5
votes
1
answer
166
views
Implementing a LoRA wrapper for Conv2D in Tensorflow
I have recently been trying to port a LoRA for CNN method originally implemented in PyTorch to TensorFlow, but my implementation did not work well, and I require assistance in making it work.
My code ...
2
votes
2
answers
120
views
getting a tensor of shape (32,) instead of a single value as a label
when i try to print/plt.tile the label of an image, its printing the tensor(32,) instead of a single label value. When i tried to print before the resizing, it was printing fine.
Code:
####
# ...
2
votes
0
answers
42
views
what is the purpose of training=True argument? Is it an argument of keras.sequential() or not? [duplicate]
What is the purpose of training=True argument in the last line. I called help(tf.keras.Sequential) but could not find anything related to it. Also is it the argument of tf.keras.Sequential() or not
...
1
vote
1
answer
57
views
TensorFlow Custom Training Loop with Mixed Precision Causing NaN Loss After Epoch 15
I am implementing a custom training loop in TensorFlow 2.18 with mixed precision (float16) for a large vision transformer model. The training runs fine for about 15 epochs, but then the loss suddenly ...
1
vote
1
answer
90
views
TensorBoard doesn't show weights for each layer
I'm trying to use TensorBoard to monitor weights and bias of a two inputs neural network, composed by two independent submodels. I'm using keras==3.11.3 with tensorboard==2.20.0 and this is callback I'...
2
votes
0
answers
62
views
Write_grads no more present on latest version of Keras
I'm having some issues with the training of a convolutional neural network, as the loss initially decreases but suddenly it becames nan. I guess the problem could be related to some exploding/...
1
vote
1
answer
38
views
Do I need .repeat() or steps_per_epoch when training on a finite TFRecord dataset in Keras?
I’m following this tutorial on 3D brain tumor segmentation using MedicAI and Keras
In the tutorial:
dataset = dataset.batch(batch_size).prefetch(tf.data.AUTOTUNE)
The author does not use .repeat(...
1
vote
0
answers
54
views
Can I convert .keras model to .h5 so that tensorflow 2.10 can use it for prediction?
I trained a keras sequential model while working in colab. Now I shifted to a PC with Windows 11. jupyter notebook with Tensorflow 2.10 is unable to read that model. it needs a model in the old .h5 ...
0
votes
2
answers
63
views
Tensorflow gradient returns None
I am being implementing a custom layer that returns both the transformed output and an auxiliary loss term. The forward pass works fine, but when I try to compute gradients, I get None for the main ...
1
vote
0
answers
111
views
Unable to load an hdf5 model file in TensorFlow / Keras
I was given an hdf5 model file that was build with tensorflow / keras. Training data is no more available.
Note: all Python code snippets shown hereunder are run against Python 3.9.23 inside a ...
0
votes
1
answer
118
views
ValueError: Only instances of keras.Layer can be added to a Sequential model when using TensorFlow Hub KerasLayer
I’m trying to build a Keras Sequential model using a feature extractor from TensorFlow Hub, but I’m running into this error:
ValueError: Only instances of `keras.Layer` can be added to a Sequential ...
1
vote
1
answer
126
views
Keras Model throwing Error while integrating with frontend [closed]
I trained a model on Colab for my final year project EfficientNetB0. After all the layer training, I tested it and its result was excellent, but now I want to integrate the model to the frontend web ...
3
votes
0
answers
78
views
Multimodel for image captioning with CNN and LSTM over flickr30k does not learn. How to fuse image features and word embeddings?
I'm working on an image captioning project using a simple CNN + LSTM architecture, as required by the course I'm studying. The full code is available here on GitHub (note: some parts are memory-...
1
vote
1
answer
73
views
Mask image in tensorflow
Can I use keras.Layers to build custom layer to mask to whole dataset and return masked dataset. That is
class AttnMask(Layer):
def __init__(self, img_size, attention_map):
super()....
0
votes
0
answers
84
views
How to load a model while ignoring unbuilt head layers? (`expected 2 variables, received 0`)
I’m loading a costume ViT backbone saved via MLflow’s TensorFlow flavor (Keras 3). The artifact includes backbone parts I want (patch_embed, encoder) a couple of layers in the encoder were saved in a ...
1
vote
3
answers
78
views
Why isn't my keras model throwing and error when different sizes are passed to the dense layer?
I am working on a dynamic time series multi-class segmentation problem with keras (tensorflow version 2.12.0), and I wanted to see what would happen when I dropped in a dense layer into the network ...
0
votes
1
answer
173
views
Best method to create generator for TensorFlow with list of array inputs
I am using TensorFlow/Keras to create a deep learning model. The network is built as follows:
inps = []
features = []
for i in range(number_windows):
inp = Input(shape=(window_length,), name=f&...
3
votes
1
answer
212
views
TensorFlow data loader from generator error "Dataset had more than one element"
I am trying to implement a TensorFlow dataset from a Python generator because I am having problems with my model consuming memory, inevitably resulting in a OOM crash (see my question on that here). ...
0
votes
0
answers
77
views
KFold cross-validation in Keras: model not resetting between folds (MobileNet backbone)
I am trying to perform KFold cross-validation on a Keras model. The first fold runs exactly as expected, but from the second fold onwards the model doesn’t seem to reset. The training behaves ...
2
votes
1
answer
94
views
How do I format my a tensorflow dataset for a multi output model?
I have an image dataset where each image has multiple categorical features that I want to predict. I am getting this error when trying to train:
ValueError: y_true and y_pred have different structures....
2
votes
0
answers
168
views
TensorFlow/Keras model accumulates system and GPU RAM during training
I am training a model using TensorFlow/Keras using TensorFlow 2.19.0/Keras 3.10.0. During training, I monitor nvidia-smi and top, and the system RAM and the GPU RAM increase during the training period....
0
votes
1
answer
69
views
TensorFlow Serving significantly slower than Keras model.predict()
I'm deploying a Keras model using TensorFlow Serving, but the inference time is significantly slower compared to calling model.predict() directly in Python.
Running model.predict(input) on a batch of ~...
0
votes
1
answer
58
views
Keras loading the model: TypeError: too many positional arguments
When loading the model I am getting:
TypeError: too many positional arguments
model = load_model(model_path)
^^^^^^^^^^^^^^^^^^^^^^
File "/Users/moo/code/xxx/....
-1
votes
1
answer
79
views
Keras ResNet model trains but does not evaluate [closed]
I am trying to use Keras' implementation of ResNet50 and adapting it to work on the tiny-imagenet dataset from huggingface.
I can use the model to train on the data and collect training and validation ...
0
votes
0
answers
34
views
How to deploy .keras and .joblib models in FRDM MXCN947 (NXP) Microcontroller?
I have created 3 models (a RF, CNN-LSTM and a MLP) to be deployed in the FRDM MCXN947 microcontroller.
They have sizes of 2.18 GB, 7.75 MB and 0.186 MB respectively. I have saved the RF model as ....
0
votes
1
answer
98
views
Difference between Tensorflow/Keras Dense Layer output and matmul operation with weights with NumPy
I was trying to mimic the result of a simple Tensorflow/Keras Dense layer with NumPy (forward pass only) and I was surprised not to have the exact same result.
A dense layer output is just the product ...
0
votes
0
answers
47
views
Can I save and load a Keras Model with Feature Names added?
I have data where I need to use numpy's get_dummies to convert the One Hot Encoding. When I train from a larger dataset I get all the possible encodings. When I predict I could possible only have a ...
0
votes
2
answers
74
views
unable to load a model with Keras
I wanted to create a speech recognition application and I was following this tutorial : Transformer ASR.
After training it for 1 epoch, I saved the model and it saved successfully:
model.save("...
0
votes
1
answer
72
views
ValueError: The layer sequential_4 has never been called and thus has no defined input
I have built a CNN model with the following layers:
def build_trainable_cnn(input_shape, num_classes):
"""
Create a CNN model for feature extraction
Parameters:
...
0
votes
1
answer
29
views
ValueError: as_list() is not defined on an unknown TensorShape. Error with lambda function
I'm trying to build and train a model with keras, but I'm facing the error "ValueError: as_list() is not defined on an unknown TensorShape.".
Follows the most bare bone code I could build ...
2
votes
1
answer
112
views
How to handle loss function with sparse output
I'm trying to create a ML model in TensorFlow that takes in a tensor with shape (128,128,12) and outputs a tensor with shape (128,128,3), where the output dimensions mean (x, y, sensor_number).
With ...
1
vote
1
answer
54
views
Quantizing tfjs model to float16 ValueError: Missing output_path argument
I'm trying to quantize a tfjs model to float16 from the standard float32. This is how I loaded my .keras model and converted it to tfjs. This part works.
keras_input_file_path = '/content/cnn_model....
0
votes
1
answer
66
views
Keras AUC metric breaking on a multi-class problem
I'm attempting to train a multi-class image classification model based on standardised 128x128 images. When I use "accuracy" alone as a metric, I have no issues. When I introduce AUC, I can'...
2
votes
0
answers
214
views
tf.keras: Why my UNet with final layer Conv3D with sigmoid activation gives probabilities less than 0 and more than 1
I am really confused because this should never happen according to common sense and to all things that I found on the internet.
In short. My UNet with sigmoid activation as last layer gives ...
1
vote
0
answers
69
views
Tensorflow - validation metric does not show up, it gets the same name as the train metric
I am using the model.compile(metrics=[MyMetric])
I was wondering why I only see loss and val_loss, but only se my_metric and not val_my_metric after the evaluation at end of each epoch completes.
I ...
0
votes
1
answer
62
views
Problem in fine tuning DeepLabV3Plus using keras_cv for Semantic Segmentation
I'm using open-images-v7 dataset (accessing via fiftyone lib) and keras_cv lib to fine tune DeepLabV3Plus with mobilenet_v3_small backbone, but the accuracy doesn't improve with epochs at all, and I'm ...
1
vote
1
answer
69
views
Python/TensorFlow: Persistent RAM increase in a long-running loop despite clear_session and gc.collect
I'm running a Python script on a VPS in a continuous loop. The script fetches stock data with yfinance, then trains a new TensorFlow/Keras model for each stock.
Problem: The process's RAM usage ...
1
vote
0
answers
82
views
Byte Shifting Error White Reading Safetensor File in C
I'm trying to read safetensors file in C. As a read on Huggingface's documentation, I'm taking first 8 byte of file for header size;
...
uint64_t header_size = 0;
int read_header_size = fread(&...
0
votes
0
answers
103
views
How to convert discrete choices (of a color) from neural network output to colors directly in tensorflow?
Context: I am learning to use tensorflow and want to do a simple experiment where I provide a neural network with 4 color choices for each pixel. The network should learn to pick the best colors from ...
0
votes
0
answers
72
views
How to speed up Keras Tuning on multi core machine?
This question is related to the Distributed hyperparameter tuning strategy of keras tuner to get the possible hyperparameters for my model. The search space is huge. The worker thread is as in the ...
0
votes
1
answer
133
views
tensorFlow GPU slower than CPU, ptxas warning
I was trying to make a model testing series I ran into some horrible compilation behavior.
The model runs about 5x faster on my CPU (Xeon W-2225, 4 core) than on my RTX 3060 (12GB) OR on my T1000 (4GB)...
0
votes
1
answer
85
views
ImportError: cannot import name 'applications' from 'tensorflow.python.keras'
I am encountering issues importing the applications library to utilize the EfficientNetB0 model in an image classification model training.
I have reviewed the TensorFlow documentation, and supposedly, ...
1
vote
1
answer
204
views
Grid search scikeras error : 'super' object has no attribute '__sklearn_tags__'
I am trying to run a gridsearch in my pycharm jupyter notebook.
Getting 'super' object has no attribute '__sklearn_tags__' error. This question was asked for RandomizedSearch previously, but none of ...