Questions tagged [functional-api]
37 questions
11
votes
1 answer
Multi-input Multi-output Model with Keras Functional API
As described in figure 1, I have 3 models which each apply to a particular domain.
The 3 models are trained separately with different datasets.
And inference is sequential :
I tried to parallelize the call of these 3 models thanks to the…

Kibs J.
- 133
- 1
- 1
- 9
3
votes
2 answers
Difference between the input shape for a 1D CNN, 2D CNN and 3D CNN
I'm first time building a CNN model for image classification and i'm a little bit confused about what would be the input shape for each type (1D CNN, 2D CNN, 3D CNN) and how to fix the number of filters in the convolution layer. My data is…

Andrea
- 113
- 1
- 7
2
votes
0 answers
Model not training when using batch normalization with keras functional API
I'm going through some tutorials using the Keras functional API in Tensorflow 2, and I'm having some trouble including BatchNormalization layers when using the functional API.
Using roughly the same code:
This network trains with the sequential API…

James Stieger
- 21
- 2
1
vote
0 answers
Keras functional API can not save right weights in h5 files
I have used functional API to build a ResNet neural network algorithm. However, this constructed model can not save the neural networks' weights in an appropriate result. The validated result was very good. But the inference result is very bad.
When…

张家瑜
- 11
- 2
1
vote
1 answer
How to set class weights in keras model for multiclass classification problem?
I am building an emotion recogniton model that receives both text and audio features. The dataset that I am using has 3 classes (Neutral, negative and positive). Due to the dataset being higly imbalanced I want to use class weight argument in fit…

Rodrigo Lemos
- 55
- 5
1
vote
0 answers
Keras Functional API: Remove the square brackets of output shape of my Input Layer
Not Sequential API, but for Keras Functional API, how do I remove the '[]' of my output shape? For example, I don't want [(None,32)] instead, i want (None,32):
i = Input(shape=(32,))
x = Dense(16, activation='softmax')(i)
model = Model(x,…

kaispace30098
- 120
- 8
1
vote
1 answer
The performance of a model with different output loss configurations in Sequential and Functional APIs differ in Keras
I am getting two very different results from the model coded in Sequential and Function APIs. What could go wrong with my code?
I started my code with the following:
np.random.seed(42)
tf.random.set_seed(42)
random.seed(42)
Then, I coded the…

MM Khan
- 203
- 1
- 2
- 7
1
vote
0 answers
How to remove batch normalization layers from a Keras model?
I would like to remove all the batch normalization layers from a Keras model that includes short-skip connections. For example, let's consider EfficientNetB0 as follow:
import tensorflow as tf
model =…

Ali
- 11
- 2
1
vote
0 answers
Tensorflow functional API
num_tags = 12
num_words = 10000
num_departments = 4
title_input = keras.Input(
shape=(None,), name="title"
)
body_input = keras.Input(shape=(None,), name="body") # Variable-length sequence of ints
tags_input =…

Joshua Jenny Sibbu
- 51
- 3
- 11
1
vote
1 answer
How to use Embedding Layer along with textvectorization in functional API
Just starting on tensorflow
Working on imdb dataset. Process: Text encoding using textvectorization layer and passing it to embedded layer:
# Create a custom standardization function to strip HTML break tags '
'. def…
'. def…

Jay ra1
- 61
- 6
1
vote
0 answers
Functional API or Custom Layer keras tensorflow
I was building a neural network in tensorflow keras and ended up with the following code as a step in the model:
enc = tfkl.Reshape((-1, 20,input_shape[1]))(input_layer)
encoder_output = []
for i in range(enc.shape[1]):
o = encoder(enc[:, i,…

James__pxlwk
- 71
- 1
- 7
1
vote
0 answers
InvalidArgumentError: assertion failed: [predictions must be >= 0] [Condition x >= y did not hold element-wise:] while using LSTM in Functional API
My code runs perfectly fine up-to Epoch 5 and I see this warning message (WARNING:tensorflow:Early stopping conditioned on metric `val_prc` which is not available. Available metrics are: loss,tp,fp,tn,fn,accuracy,precision,recall,auc,prc…

Spandyie
- 914
- 2
- 11
- 23
1
vote
0 answers
Keras functional API gets poor result when combining text and structured data
I have a set of structured features (that gets about 0.70 accuracy alone) and a text field (that gets about 0.85 accuracy alone) associated to each record. I have developed a classification model that accepts both structured and text data using…

Hasan Zafari
- 355
- 2
- 6
1
vote
1 answer
How to create a model with multiple shared layers in Keras Functional API?
I would like to have a model with 2 inputs, several hidden layers with shared weights, then separate output layers.
I have seen this question and its accepted answer: Share weights between two dense layers in keras . This is exactly what I would…

leevii
- 65
- 1
- 11
1
vote
2 answers
Is it possible to create a model in Keras Functional API without an input layer?
I would like to create a model consisting of 2 convolutional, one flatten, and one dense layer in Keras. This would be a model with shared weights, so without any predefined input layer.
It is possible to do using the sequential way:
model =…

leevii
- 65
- 1
- 11