All Questions
Tagged with tf.keras neural-network
103
questions
16
votes
6
answers
49k
views
InvalidArgumentError: required broadcastable shapes at loc(unknown)
Background
I am totally new to Python and to machine learning. I just tried to set up a UNet from code I found on the internet and wanted to adapt it to the case I'm working on bit for bit. When ...
13
votes
7
answers
25k
views
Keras that does not support TensorFlow 2.0. We recommend using `tf.keras`, or alternatively, downgrading to TensorFlow 1.14
I am having an error regarding (Keras that does not support TensorFlow 2.0. We recommend using tf.keras, or alternatively, downgrading to TensorFlow 1.14.) any recommendations.
thanks
import keras
...
8
votes
2
answers
4k
views
What is the difference between conv1d with kernel_size=1 and dense layer?
I am building a CNN with Conv1D layers, and it trains pretty well. I'm now looking into how to reduce the number of features before feeding it into a Dense layer at the end of the model, so I've been ...
7
votes
1
answer
8k
views
What is the difference between input_shape and input_dim in keras?
Currently i am learning deep learning and stumbled upon these confusion:
when to use input_shape and input_dim parameter.
shape of my data is (798,9) and these has 8 input variable and 1 output ...
6
votes
1
answer
2k
views
WARNING:tensorflow:`write_grads` will be ignored in TensorFlow 2.0 for the `TensorBoard` Callback
I am using the following lines of codes to visualise the gradients of an ANN model using tensorboard
tensorboard_callback = tf.compat.v1.keras.callbacks.TensorBoard(log_dir='./Graph', histogram_freq=...
5
votes
2
answers
11k
views
keras : add layers to another model
I need to add layers to an existing model. However, I need to add the layers at "the main model level", that is I can't use the classic functional approach. For example, if I use something ...
5
votes
1
answer
2k
views
Keras evaluate the validation data before the epoch ends
I'm want to train my model with Keras. I'm using a huge dataset Where one training epoch has more than 30000 steps. My problem is that I don't want to wait for an epoch before checking the model ...
4
votes
1
answer
2k
views
How to implement a neural network with a not-fully-connected layer as the final layer?
I would like to implement a neural network with an input layer, two dense hidden layer and a non-dense output layer. A toy example is shown in the figure below. The first hidden layer has three ...
4
votes
2
answers
4k
views
TypeError: You are attempting to use Python control flow in a layer that was not declared to be dynamic. Pass `dynamic=True` to the class constructor
I am using TensorFlow 2.0.0 and tf.keras to create a model network that takes in n inputs, [x1,x2,x3,x4,x5,...xn], and computes f(x1,x2,x3,x4,x5,...xn).
I have defined my model below as:
def ...
4
votes
1
answer
2k
views
ValueError: Operands could not be broadcast together with shapes (54, 54, 128) (54, 54, 64)
I wrote a ResNet block with three convolutional layers:
def res_net_block(input_data, filters, kernel_size):
kernel_middle = kernel_size + 2
filters_last_layer = filters * 2
x = Conv2D(filters, ...
4
votes
2
answers
5k
views
tf.keras loss becomes NaN
I'm programming a neural network in tf.keras, with 3 layers. My dataset is the MNIST dataset. I decreased the number of examples in the dataset, so the runtime is lower. This is my code:
import ...
4
votes
2
answers
1k
views
Training multiple models in series in Keras for hyperparameter optimization
The idea is to train multiple models using the same training dataset, changing some parameters each time in order to see which parameter works best. In order to do so I would need every model to be ...
3
votes
1
answer
3k
views
How to access and visualize the weights in a pre-trained TensorFlow 2 model?
So, I have re-trained a pre-trained ResNet50 V2 model in TensorFlow 2 using the tf.keras framework with two Dense layers added to the top. Now I want to visualize the weights in the layers within the ...
3
votes
1
answer
3k
views
TensorFlow/Keras Using specific class recall as metric for Sparse Categorical Cross Entropy
*Update at bottom
I am trying to use recall on 2 of 3 classes as a metric, so class B and C from classes A,B,C.
(The original nature of this is that my model is highly imbalanced in the classes [~90% ...
3
votes
1
answer
3k
views
Changing the learning rate after every step in Keras
I want to increase the learning rate from batch to batch inside of one epoch, so the first data the Net sees in one epoch has low learning rate and the last data it sees has high learning rate. How do ...
3
votes
3
answers
1k
views
How to overfit data with Keras?
I'm trying to build a simple regression model using keras and tensorflow. In my problem I have data in the form (x, y), where x and y are simply numbers. I'd like to build a keras model in order to ...
3
votes
1
answer
557
views
Differential learning Rates - Keras
I was reading an article called Differential Learning Rates on Medium and was wondering if this could be applied in Keras. I was able to find this technique implemented in pytorch. Is this possible to ...
2
votes
1
answer
861
views
mse loss function not compatible with regularization loss (add_loss) on hidden layer output
I would like to code in tf.Keras a Neural Network with a couple of loss functions. One is a standard mse (mean squared error) with a factor loading, while the other is basically a regularization term ...
2
votes
1
answer
3k
views
tf.keras predictions are bad while evaluation is good
I'm programming a model in tf.keras, and running model.evaluate() on the training set usually yields ~96% accuracy. My evaluation on the test set is usually close, about 93%. However, when I predict ...
2
votes
0
answers
67
views
Strange differences in tf.keras model construction in versions 1.4 and 2.0
I have noticed differences in net topology building in tf.keras in 1.4 and 2.0 versions. I'd like to build net with sharing layers like that:
digit_input = keras.layers.Input(shape=(27, 27, 1))
...
2
votes
0
answers
363
views
How to prune weights in Tensorflow CNN model (Without migrating model to Keras)
I have a TF CNN model and now I want to use the weight pruning API of tensor flow with this but all the examples I checked online, it works only with Keras model
I want to prune wights of my ...
2
votes
0
answers
584
views
TimeDistributed Layer: Incompatible shapes: [32,3,3] vs. [32,3]
I have a model that was working before, but now it does not work. It gives an error about:
InvalidArgumentError: Incompatible shapes: [32,3,3] vs. [32,3]
[[{{node Nadam/gradients/loss/...
1
vote
3
answers
664
views
Unable to perform Grid Search for models receiving more than one input (Keras)
I have created final_model that receives two inputs (sequences of length 8). Each of them is processed by two different models, model_A and model_B. Then the two outputs are merged returning the ...
1
vote
1
answer
596
views
Keras LearningRateScheduler callback on batches instead of epochs
I am using Tensorflow 2.x, The below is the custom learning rate scheduler which i have written
def scheduler(epoch):
if epoch == 1:
return 3e-5
else:
return 3e-5 * (1/(1 + 0.01 * epoch ))...
1
vote
1
answer
505
views
Removing gaussian noise layer after training?
I was wondering if there is a way in which I can remove a gaussian noise layer
tf.keras.layers.GaussianNoise(0.1),
after using.
model.fit()
so that when using my neural net in applications it ...
1
vote
1
answer
71
views
MLP Loss calculated as NaN
I am trying to prepare a MLP model for a time-series data. Its parameters are:
Model is Sequential
Layers:
a- Hidden layer: One dense layer, with 100 nodes
input_dim = flattened array of my input ...
1
vote
1
answer
435
views
How to predict label for new input values using artificial neural network in python
I am new in machine learning. I am making a Streamlit app for multiclass classification using artificial neural network. My question is about the ANN model, not about the Streamlit. I know I can use ...
1
vote
1
answer
114
views
Precison issue with sigmoid activation function for Tensorflow/Keras 2.3.1
Assuming the following forward pass in a classic ANN
(Based on https://mattmazur.com/2015/03/17/a-step-by-step-backpropagation-example/):
Now let's use a sigmoid activation on that, I get:
So far so ...
1
vote
1
answer
160
views
With working code: simple neural network (`y = 2 * x`)
I'm a beginner with neural networks and machine learning (hence the simple y = 2 * x that I want the model to learn). I explain what I know first, with the minimal working example at the end.
The ...
1
vote
1
answer
912
views
How to use GPU and CPU in tensorflow (keras)?
I am running a rather memory-intense (estimated to be around 6GB) GAN model with tf.keras which my GPU doesn't seem to be able to handle (predicting fails, reports only nans). Is there a way to ...
1
vote
1
answer
246
views
Using ResNet50 multiples times with different inputs (weights shared)
I would like to use the same ResNet50 multiple times with different inputs, i.e. weights shared. Below is my coce but I'm getting the error message AttributeError: 'Tensor' object has no attribute '...
1
vote
1
answer
95
views
Keras Dense models with shared weights
I would like to create a Dense model in keras with shared weights. My approach is described below. I have one Dense network called dense. dense_x, dense_y and dense_z should share weights (i.e. use ...
1
vote
1
answer
672
views
Create tf.keras.add Layer when Subclassing tf.keras.Model
Objective: build a neural net with skip connections, where the number of blocks is a parameter, and we subclass tf.keras.Model.
Problem: When subclassing tf.keras.Model we define the network layers in ...
1
vote
1
answer
1k
views
KERAS-Instructions for updating: Colocations handled automatically by placer
I am Using Keras Library For my Neural Network error. While using Dropout I got the 3 following warning
WARNING:tensorflow: colocate_with (from tensorflow.python.framework.ops) is deprecated and ...
1
vote
0
answers
16
views
Extracting intermediate layer of saved model in keras. That intermediate layer is another sub-model defined in main model
Here is my architecture.
def model1():
inputs = layers.Input(shape=(x1.shape[-2],x1.shape[-1]), name='Input_layer')
x = layers.Reshape((x1.shape[-2], x1.shape[-1], 1), name='Input_reshape')(...
1
vote
0
answers
76
views
How can I create a learnable parameter or weight vector whose values are either 1 or -1
I need to build a neural network which is known as learnable parameter or a weight vector. In that way, only one vector will be generated and multiplied with the data. I have created that as following:...
1
vote
1
answer
114
views
How to get rid of ridiculously high loss when data is already normalized?
I have 500 sample of housing data which I have converted all to numbers. It has 12 columns which are used to predict 1 price.
However, when I try to run the model, its loss is massive(14 digit loss). ...
1
vote
0
answers
136
views
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, ...
1
vote
1
answer
58
views
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....
1
vote
1
answer
268
views
Store weights of multiple Keras models in one variable/array
I am new to Deep Learning.
I have 3 keras model. I am trying something like this:
weights = [] # or some data type
for i in range(3):
weights[i] = model[i].get_weights()
I want to store the ...
1
vote
0
answers
132
views
How to change an tensor of shape (726,) to (None,726)?
I wanted to create a custom loss function that suppresses all the prediction values except the highest one to zero like this:
def loss_function(y_true, y_pred):
th=[tf.math.argmax(y_pred[i]) for i ...
1
vote
0
answers
120
views
Multi-branch neural network does not learn dependencies
I am currently trying to learn using a multi-branch neural network. The underlying data looks something like the following table:
Var_1
Var_2
Var_3
a_1
a_2
a_3
a_1
a_2
c_3
b_1
b_2
b_3
b_1
b_2
a_3
...
1
vote
0
answers
147
views
Input tensors to a Functional must come from `tf.keras.Input`
model = Sequential([
Dense(64, input_dim=X_train.shape[1]),
Dense(64),
Dense(32),
Dense(32),
Dense(16),
...
1
vote
1
answer
178
views
Is it possible that the number of parameters is different even though the neural network model has the same structure?
I'm trying to make 2 Fully-Connected DNN models with the same structure to copy the weights of one to another later.
Since they have the same structure, I don't have to make different codes so I used ...
1
vote
2
answers
149
views
Neural network only predicts one class
my model only predicts one class from binary class. The model takes a video input using Keras Video Frame Generator and get 350 frames for each video. The model must take an input sequences of 350 ...
1
vote
0
answers
153
views
How to extract an equation behind the trained DNN model using tf.keras
Is it possible to extract an equation behind the trained model using Keras/Tensorflow with multiple hidden layers and 64 neurons. For example I have two input variables x1 and x2 and ine outout ...
1
vote
0
answers
84
views
ValueError: No gradients provided for any variable - No gradients in GANs generator model
I'm currently coding a GAN to generate sequences. Both the generator and the discriminator are working, when trained standalone. As soon as I combine both to the complete GAN model (to train the ...
1
vote
1
answer
184
views
Validation accuracy on MNIST differs when training data in one go vs when separated
I have a 27G dataset to analyse, and because of the size of my RAM I can't feed all my data into my Neural Network at once, and I have to import bits of it, learn on them, and then another part, so ...
1
vote
0
answers
330
views
How to define a custom loss function for a multi-dimensional target
I'm working with Tensorflow 2.0 and I'm using a normal sequential layer.
I'm trying to define a custom loss functions which does the following:
takes some elements of the input
computes their sum ...
1
vote
1
answer
2k
views
Implementation of BERT in keras with TF_HUB
I was trying to implement the Google Bert model in tensorflow-keras using tensorflow hub. For this I designed a custom keras layer "Bertlayer" . Now the problem is when I am compiling the keras model ...