Questions tagged [keras-2]

with a new API.

Keras API will now become available directly as part of

264 questions
1
vote
0 answers

keras.metrics.AUC() for a ternary classification problem

I am using Keras 2.3.1 For a ternary (3 classes) classification problem. I use the keras.metrics.AUC() as the metric. I see val_auc_3 at the end of each epoch. I am wondering to know if "val_auc_3" is the average AUC (i.e. [auc(class1 vs all) +…
1
vote
1 answer

How to use the first layers of a pretrained model to extract features inside a Keras model (Functional API)

I would like to use the first layers of a pre-trained model --say in Xception up and including the add_5 layer to extract features from an input. Then pass the output of the add_5 layer to a dense layer that will be trainable. How can I implement…
user8270077
  • 4,621
  • 17
  • 75
  • 140
1
vote
1 answer

what happens when you merge branches in keras with different shapes?

Following is the partial code. I am trying to understand what "add" does. Why is the output of Add layer (None, 38, 300) when adding two inputs with different shapes here? Following is the code in Keras. image_model = Input(shape=(2048,)) x =…
user3267989
  • 299
  • 3
  • 18
1
vote
0 answers

How does model.evaluate in Keras work and how to recreate it manually?

How does Keras' model.evaluate() work? In particular, how does the batch_size argument affect the calculation? The documentation says the loss/metrics are calculated as averages over the batches. However, as there is only one scalar output for each…
Polhek
  • 67
  • 1
  • 7
1
vote
1 answer

Stacking fully connected layers on top of two autoencoders for classification

I'm training autoencoders on 2D images using convolutional layers and would like to put fully connected layers on top of encoder part for classification. My autoencoder is defined as follows (just a simple one for illustration): def…
machinery
  • 5,972
  • 12
  • 67
  • 118
1
vote
0 answers

What is the Keras concatenation output like

I'm trying to concatenate two hidden states of a 2-Bi-LSTM layers but i want to know first what is the output shape of a concatenation. Moreover, I would like to know what are the attention mechanisme. To be more explicit how can i do it for two…
AMTA
  • 39
  • 4
1
vote
1 answer

Reasoning about MNIST database

I cannot download the Keras MNIST db the simple way due to proxy. So I have downloaded a local version from here : https://s3.amazonaws.com/img-datasets/mnist.pkl.gz I am importing that to my notebook with the following code : import gzip import…
Simon Kiely
  • 5,880
  • 28
  • 94
  • 180
1
vote
1 answer

Early stopping does not work in my code in keras with TensorFlow

When I am using early stopping the model trains for one epoch only, which is not what should be doing. Here is the example without early stopping: # split a univariate sequence into samples def split_sequence(sequence, n_steps): X, y = list(),…
user8270077
  • 4,621
  • 17
  • 75
  • 140
1
vote
1 answer

Cannot import a method from a module in keras

I have installed Tensorflow 2.0 print(tf.__version__) 2.0.0-alpha0 While I can use the to_categorical method I can not import it. import tensorflow as tf tf.keras.utils.to_categorical(np.arange(4), num_classes = 4) array([[1., 0., 0., 0.], …
user8270077
  • 4,621
  • 17
  • 75
  • 140
1
vote
0 answers

What keras updates make error of this simple code?

To use multi-GPU, I upgrade keras(1.2.0 --> 2.2.4) version. I don't change any of code, but there is an error. What is the reason of this ERROR? I attached the reproducible code below. As you can see A & B have same shapes, but only testB got the…
남현준
  • 31
  • 2
1
vote
1 answer

ValueError: `validation_data` should be a tuple `(val_x, val_y, val_sample_weight)` or `(val_x, val_y)`. Found: <__main__.Generator object at>

I know that got asked already a few time but no answer fit my bill. I have a csv file with text (newspaper content) and label, column 0 and 1. I am trying to write my first custom generator for text classification but getting the error ValueError:…
osterburg
  • 447
  • 5
  • 24
1
vote
1 answer

Exception in Sequence-to-Sequence model in Keras

I am trying to build a sequence to sequence model in Keras using LSTM and dense neural network. The encoder encodes the input, the encoded state and the inputs are then concatenated and fed into a decoder which is an lstm + dense neural network…
Abdul Rahman
  • 1,294
  • 22
  • 41
1
vote
0 answers

Keras2.0 implement by theano backend

I am a new keras learner,i have some question, here is my code: from keras.layers import Input img = Input(batch_shape=(10, 3, 32, 32), name='input_img') print(img.shape) If I use tensorlow backend , it's print (10, 3, 32, 32). but if i use theano…
1
vote
1 answer

tf.sparse_to_dense: Shape must be rank 1 but is rank 0

My codes: def f(x): try: import tensorflow as tf # x is (None, 10, 2) idx = K.cast(x*15.5+15.5, "int32") z = tf.sparse_to_dense(idx, 32, 1.0, 0.0, name='sparse_tensor') …
BAE
  • 8,550
  • 22
  • 88
  • 171
1
vote
0 answers

How to convert caffe layers to keras layers?

I found the following layers in caffe prototxt file: layer { name: "before_proj" type: "Silence" bottom: "xxxbefore_proj" } layer { name: "1_before_proj" type: "InnerProduct" bottom: "conv4f" top: "xxx1_before_proj" param { …
BAE
  • 8,550
  • 22
  • 88
  • 171