All Questions
26,860 questions
0
votes
0
answers
12
views
Deploying Keras model for prediction in Google Cloud Functions
I've been trying to deploy a very simple toy Keras model to Cloud Functions, which would predict the class of an image, but for reasons unknown, when the execution gets to the predict method, it gets ...
0
votes
0
answers
30
views
Shape of inputs causing issues with CNN with numerical and text inputs
I am having an issue of where I am obtaining an error to do with the input shapes for the CNN model.
The code for the model
text_input = Input(shape = (max_len,), name = 'text_input')
numerical_input =...
0
votes
0
answers
30
views
Rstudio:Tensorflow and Keras both installed but failed to load due to No module named 'tensorflow'
I am now working on my class essay and I'm trying to create a CNN in RStudio.
At first the No module named tensorflow error message appeared when I tried to run the code:
layer_dense(units=1,...
0
votes
0
answers
26
views
How to combine multiple models into one by combining pre-trained layers using Keras
I have multiple models pretrained to classification. I want to combine them into one model. Each of those models contain the same EfficentNet and Resnet achitecture, then there is concatenate layer ...
-2
votes
0
answers
35
views
Do I need to call model.fit() function every time after loading the model using Keras [closed]
I am using Keras to create model :
def my_model():
model = Sequential()
model.add(Conv2D(60, (5,5), input_shape=(32,32,1), activation='relu'))
model.add(Conv2D(60, (5,5), activation='relu'))
...
0
votes
0
answers
14
views
What is the Keras 3 version of this numpy function of this IEEE754 to Unsigned Integer 8 normalization?
Using the Keras 3 ops api, what is the Keras 3 version of this normalization function?
def ieee754_to_uint8(x, axis=-1):
"""
Normalize a tensor using IEEE 754 logic and map it to ...
-1
votes
0
answers
39
views
Struggling with Coin Classification Using TensorFlow
I'm working on a model that would classify coin categories from a self-made coin dataset.
(17 categories and around 6K augmented images)
Coin images are cropped, so background pixels are set to be ...
0
votes
0
answers
32
views
ValueError: The layer custom_res_net_6 has never been called and thus has no defined output on grad cam implementation in tensorflow
I have the following model
@register_keras_serializable()
class CustomResNet(Model):
def __init__(self, num_classes, trained = False, **kwargs):
super(CustomResNet, self).__init__(**kwargs)...
0
votes
0
answers
16
views
LSTM training fades to Nan when batch_number>=2
I am running a very simple multilayer LSTM network. I have set different transformations for the data, namely StandardScaler(), RobustScaler() and MinMaxScaler(). The code runs smooth and I get no ...
0
votes
1
answer
24
views
Could not locate class 'SinePositionEncoding'. Make sure custom classes are decorated with `@keras.saving.register_keras_serializable()`
I trained transformer with SinePositionEncoding and TransformerEncoder:
Instead of using from keras-hub from pip due to error in Windows due to numpy compatibility, I directly copy the source code ...
0
votes
0
answers
28
views
Changing BatchNormalization momentum while training in Keras 3
I'm buidling a custom model using Keras (keras 3.3.3 with python 3.9.19) and I would like to increase the momentum of my BatchNormalization layers during training.
Ideally, I'd like to use a custom ...
-3
votes
0
answers
48
views
Find all face-recognition matches in JPEG files, which are similar to a corpus of 10 example photos
This code works, with keras_facenet, to find all files in photos/*.jpg matching the face present in me.jpg:
import glob, os, cv2
from keras_facenet import FaceNet
embedder = FaceNet()
detections = ...
1
vote
1
answer
32
views
Why does pre-trained Swin Transformer encoder fail on TPU but works on CPU in Colab?
I’m working on an image segmentation task and trying to use a pre-trained Swin Transformer Large (Swin-L) encoder for the feature extraction backbone. The code runs perfectly on a CPU in Colab. ...
0
votes
1
answer
43
views
TensorFlow does not accept list type for dataset generator
I am building a neural network. I couldn't load all the training data into memory at once, so I am using TensorFlow's tf.data.Dataset.from_generator function to load data incrementally. However, it ...
0
votes
0
answers
86
views
ValueError: A KerasTensor cannot be used as input to a TensorFlow function
Well, I've had enough of this problem, I'm trying to use a Transformer XL model for a PPO task (at the moment a simplified version of pokemon, but that's not relevant).
here is the code:
import ...
0
votes
0
answers
106
views
Unrecognized keyword arguments passed to DepthwiseConv2D: {'groups': 1} error when loading the .h5 model in tensorflow colab
I'm trying to load this face anit-spoofing model. It is a MobileNetV2 model. I want to convert it to coreML format. I have uploaded the .h5 model file into the colab. But when I try to load the model ...
1
vote
2
answers
58
views
Illegal instruction (core dumped) import keras
If I try to do 'import keras', it gives core dump.
python3 -c 'import keras; print(keras.__version__)'
Illegal instruction (core dumped)
or
python3 test.py
Illegal instruction (core dumped)
I tried ...
1
vote
1
answer
31
views
Subclassed model not saved by ModelCheckpoint callback
I’m using Keras and TensorFlow 2.12.0 to implement a subclassed model with custom methods, such as a custom train_step. To save the model, I use the ModelCheckpoint callback.
My goal is to save not ...
0
votes
0
answers
29
views
How to use Keras with Optuna tuning and Sklearn Pipeline
I am developing a model using Keras and use Optuna for the hyperameter tuning.
I need to use K-fold method for the development.
However, I cannot successfully run it.
Please help.
Here is the code:
...
0
votes
0
answers
26
views
How to window a dataset with categorical and numerical data for LSTM model?
I have a dataset with 3 columns: Timestamp (string), Inverter_Key (string) (21 inverters for my case), energy (integer), temperature ( integer). I try to create LSTM model to predict energy and ...
4
votes
1
answer
46
views
keras model does not learn if using tf.data pipeline
A keras model does learn using Numpy arrays as the input, but fails to make any progress if reading data from a tf.data pipeline. What could be the reason potentially?
In particular, the model ...
-2
votes
0
answers
24
views
keep getting TypeError: load_model() missing 1 required positional argument: 'filepath' in tf version 2.15.0
I'm trying to load a model to use to for predictions, but it seems the model failed to load
my tf version: tensorflow 2.15.0
model = load_model('model.h5')
img_path = "app\model\test.jpg"
...
0
votes
1
answer
53
views
Cannot augment images with tensorflow.keras.preprocessing.image import ImageDataGenerator
I want to make an augmented version of my dataset. The dataset was manually labelled and downloaded from this RIWA dataset.
I create class with this code
source_dir = r'./river-water-segmentation-...
-2
votes
0
answers
40
views
InvalidArgumentError: only one input size may be -1, not both 0 and 1 in TensorFlow model during prediction with single image input
I'm working on a TensorFlow model for face recognition, where I preprocess images, generate embeddings, and then store them in a CSV database. The model works fine when predicting on a batch of images ...
-2
votes
0
answers
45
views
How does keras Functional API create a new model?
Extracting input and output from old model in keras to create a new model using keras Functional API create a new model similar to the old model, and I am not sure why.
Example:
import keras
from ...
0
votes
0
answers
33
views
Install Tensorflow on M1 Max Mac using Conda and VS Code
I'm having the hardest time getting Tensorflow to install on my Mac and I've tried several approaches. Searching the internet for solutions led to recreating my Conda environments, trying pip, ...
-1
votes
0
answers
20
views
Import Keras np.complex_ was removed [duplicate]
When I try to import keras or import tensorflow I get this error "AttributeError: np.complex_ was removed in the NumPy 2.0 release. Use np.complex128 instead." I tried changing the numpy ...
0
votes
0
answers
31
views
How to set non-trainable weights?
The method keras.Model.set_weights seems to only take trainable weights. Non-trainable weights such as those from normalization layers cannot be imported this way. This is problematic, since in Keras ...
0
votes
0
answers
17
views
Tensorboard histogram display of layer weights was working in tensorflow 2.12 but is broken in 2.16. Is this due to the Keras version update (2 to 3)?
The below code (a minimal 'toy' example using data generators for both training and validation data) works fine in 2.12 and produces the desired bias and kernel weight histograms in tensorboard for ...
0
votes
0
answers
34
views
"ValueError: Shapes are incompatible", but where?
I load my datasets with keras.utils.image_dataset_from_directory(). Here's the code:
train_ds = image_dataset_from_directory(
"train",
validation_split=0.2,
subset="training",...
0
votes
0
answers
22
views
Splitting AI training data to reduce load on computer [duplicate]
I am trying to train an image classifier but there is a lot of images and my computer is having problems allocating ram to it. I am getting this error
numpy._core._exceptions.MemoryError: Unable to ...
0
votes
1
answer
65
views
How to modify my code to handle RGBX (4-channel) images for semantic segmentation?
I'm new to this field and have been following a U-Net tutorial using 3-channel RGB images for semantic segmentation https://www.youtube.com/watch?v=68HR_eyzk00&list=...
0
votes
1
answer
37
views
Trouble loading the celebA dataset for vgg16 model
Im trying to use the celeba dataset for a vgg16 model, however when I try to run this code
import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow....
0
votes
0
answers
17
views
adapt() doesn't work within tf.data.Dataset.map() while building a preprocessing pipeline using keras preprocessing layers
I'm trying to create a neural network that assigns tasks to employees based on their skills (https://www.kaggle.com/datasets/umerfarooq09/skill-based-task-assignment).
The data contains categorical ...
0
votes
0
answers
28
views
understanding loss in tf keras model fit
I am trying to replicate the loss reported after training a tf.keras model. From my understanding, history.history['loss'] should return the average loss per epoch after calling model.fit. However, it ...
0
votes
0
answers
29
views
Problems with setting gradients of GAN in keras
Having some experience in developing neural networks in Keras, I decided to write a non-standard GAN, which you can't really call as such. The point is that the discriminator is a ready-made neural ...
0
votes
1
answer
70
views
How to use loaded data from kaggle in google colab( to actually work with it)
So i recently imported dataset from this https://www.kaggle.com/datasets/mostafaabla/garbage-classification website. And even though i have it in my files in google colab(unzipped and all that stuff), ...
0
votes
0
answers
29
views
Issues with Running RL Code Using TensorFlow 2.10.1 and Keras-RL 0.4.2 - Symbolic Input/Output Error
I'm currently learning machine learning and have moved from basic models and neural networks to reinforcement learning (RL). After watching a tutorial by Nicholas Renotte (link here), I tried to ...
0
votes
1
answer
53
views
Multiclass classifier using Keras from 'Deep Learning with Python' yields very different accuracy compared to what's in the textbook
Below is the code for multi class classifier from Chapter 4 in 'Deep Learning with Python' by François Chollet. The textbook mentions this code will yield >95% training accuracy, but my environment ...
0
votes
1
answer
40
views
Error in prediction step after imported a keras model to tensorflow java
my goal is to use a Keras model in a java program.
I export the keras model with model.export() and not model.save() so I get well a folder with the model in .pb format.
Then I used py .\...
0
votes
1
answer
30
views
converting keras model to tensorflow lite to use in Kivy app
I am trying to convert the keras model to tensorflow lite, and use it in the android app development using kivy
model -
model_v3 = tf.keras.applications.MobileNet(
weights='imagenet', include_top=...
0
votes
0
answers
32
views
TqdmCallback writes loss as loss=tf.Tensor(, shape=(), dtype=float32)
I have written a VAE model in Keras following this example.
The code is working as expected, however, the loss is being printed as
loss=tf.Tensor(, shape=(), dtype=float32). As seen in the picture.
...
-2
votes
1
answer
43
views
Model Always Classifies Images as Cats with High Confidence Despite Hyperparameter Tuning [closed]
I am trying to train a model on images using the code below. My directory structure is as follows:
The PetImages folder, which is approximately 1GB in size, is located next to my main.py script.
...
0
votes
0
answers
56
views
Value Error: expected axis -1 of input shape to have value 444, but received input with shape (None, 708)
I'm trying to train a FNN model for credit card fraud detection. My categorical features are merchant, category, city, and state. I also standardized my numerical features using StandardScaler. I ...
0
votes
0
answers
46
views
Cannot get this code to work. Tensorflow - custom loss function cannot process Keras intermediate Tensor
Here is the code it is a simple Tensorflow code to train multiple MLP first produce a set of weights use these as inputs to an autoencoder which is trained to encode the truth table for an XoR then ...
-1
votes
2
answers
358
views
Issue with python/keras implementation of Generative Adversarial Network (GAN) on MacBook
I'm very new to keras and Generative Adversarial Networks (GAN). When I attempted to run this script for a simple GAN on my MacBook, I got:
Traceback (most recent call last):
File "~/Library/...
0
votes
1
answer
33
views
How can I get a keras layer to learn an AND operation
To get keras to learn to detect corners from a binary image of a rectangle I reduced the problem down to classifying a 3x3 array of pixels. The top left corner, the pixels would need to look like this....
0
votes
0
answers
21
views
Keras branch model issue
I have constructed the following CNN model:
def create_model(input_shape=(128, 128, 3)):
inputs = keras.Input(shape=input_shape, name='inputs')
# main block
main_block = keras.Sequential([...
0
votes
0
answers
45
views
ValueError: A total of 18 objects could not be loaded. Example error message for object <TextVectorization name=text_vectorization, built=True>:
I am having a problem saving and load models. I have figured out it specifically has to do with the TextVectorization layer but do not know what to do from there.
Here is my code:
class ...
0
votes
0
answers
43
views
Accessing static file in flask app python
I've been making a simple website which runs an image classification model using keras on an image captured from the users webcam. At the moment, my model is saved in the static folder of my flask app....