keras

How to extract cell state of LSTM model through model.fit()?

徘徊边缘 提交于 2021-01-29 05:47:37
问题 My LSTM model is like this, and I would like to get state_c def _get_model(input_shape, latent_dim, num_classes): inputs = Input(shape=input_shape) lstm_lyr,state_h,state_c = LSTM(latent_dim,dropout=0.1,return_state = True)(inputs) fc_lyr = Dense(num_classes)(lstm_lyr) soft_lyr = Activation('relu')(fc_lyr) model = Model(inputs, [soft_lyr,state_c]) model.compile(optimizer='adam', loss='mse', metrics=['accuracy']) return model model =_get_model((n_steps_in, n_features),latent_dim ,n_steps_out)

How to fix ''ValueError: Input 0 is incompatible with layer flatten: expected min_ndim=3, found ndim=2" error when loading model

风格不统一 提交于 2021-01-29 05:33:56
问题 I'm trying to save and load my keras model. It trains, evaluates, and saves fine (using .h5 to save model) but when I try to load the model I get the following error: ValueError: Input 0 is incompatible with layer flatten: expected min_ndim=3, found ndim=2. Am I loading the model incorrectly? Any help would be appreciated! This is the code block from where I'm saving the model. def ml(self): model = tf.keras.models.Sequential() model.add(tf.keras.layers.Flatten()) self.addLayer(model,145,6)

Why Keras Lambda-Layer cause problem Mask_RCNN?

▼魔方 西西 提交于 2021-01-29 05:28:04
问题 I'm using the Mask_RCNN package from this repo: https://github.com/matterport/Mask_RCNN . I tried to train my own dataset using this package but it gives me an error at the beginning. 2020-11-30 12:13:16.577252: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcuda.so.1 2020-11-30 12:13:16.587017: E tensorflow/stream_executor/cuda/cuda_driver.cc:314] failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected 2020-11-30

Why does my CNN not predict labels as expected?

▼魔方 西西 提交于 2021-01-29 05:21:05
问题 I am new to the concept of Similarity Learning. I am currently doing a face recognition model using Siamese Neural Network for the Labelled Faces in the Wild Dataset. Code for Siamese Network Model (Consider each code snippets to be a cell in Colab): from keras.applications.inception_v3 import InceptionV3 from keras.applications.mobilenet_v2 import MobileNetV2 from keras.models import Model from keras.layers import Input,Flatten def return_inception_model(): input_vector=Input((224,224,3))

How can I change the backend of Keras dynamically?

半腔热情 提交于 2021-01-29 05:01:09
问题 Preliminary information: The answers given for the previously asked related questions (e.g., How to change the backend of Keras to Theano?, How to switch Backend with Keras (from TensorFlow to Theano)) did not work for me. Hence, I've created my own question. As the title clearly describes, I need to change the backend of Keras dynamically (per run). How can I do this? I'm using Python 3 . Here is a function that I've created through the feedback on the web: from keras import backend as K

How to implement a gaussian renderer with mean and variance values as input in any deep modeling framework (needs to be back-propagable)

有些话、适合烂在心里 提交于 2021-01-29 04:32:54
问题 Imagine a typical auto-encoder-decoder model. However, instead of a general decoder where deconvoutions together with upscaling are used to create/synthesize a tensor similar to the model's input, I need to implement a structured/custom decoder. Here, I need the decoder to take its input, e.g. a 10x2 tensor where each row represents x,y positions or coordinates, and render a fixed predefined size image where there are 10 gaussian distributions generated at the location specified by the input.

What does the `order` argument mean in `tf.keras.utils.normalize()`?

风流意气都作罢 提交于 2021-01-29 03:50:34
问题 Consider the following code: import numpy as np A = np.array([[.8, .6], [.1, 0]]) B1 = tf.keras.utils.normalize(A, axis=0, order=1) B2 = tf.keras.utils.normalize(A, axis=0, order=2) print('A:') print(A) print('B1:') print(B1) print('B2:') print(B2) which returns A: [[0.8 0.6] [0.1 0. ]] B1: [[0.88888889 1. ] [0.11111111 0. ]] B2: [[0.99227788 1. ] [0.12403473 0. ]] I understand how B1 is computed via order=1 such that each entry in A is divided by the sum of the elements in its column. For

What does the `order` argument mean in `tf.keras.utils.normalize()`?

为君一笑 提交于 2021-01-29 03:45:02
问题 Consider the following code: import numpy as np A = np.array([[.8, .6], [.1, 0]]) B1 = tf.keras.utils.normalize(A, axis=0, order=1) B2 = tf.keras.utils.normalize(A, axis=0, order=2) print('A:') print(A) print('B1:') print(B1) print('B2:') print(B2) which returns A: [[0.8 0.6] [0.1 0. ]] B1: [[0.88888889 1. ] [0.11111111 0. ]] B2: [[0.99227788 1. ] [0.12403473 0. ]] I understand how B1 is computed via order=1 such that each entry in A is divided by the sum of the elements in its column. For

How to apply a different dense layer for each timestep in Keras

天涯浪子 提交于 2021-01-29 02:22:33
问题 I know that applying a TimeDistributed(Dense) applies the same dense layer over all the timesteps but I wanted to know how to apply different dense layers for each timestep. The number of timesteps is not variable. P.S.: I have seen the following link and can't seem to find an answer 回答1: You can use a LocallyConnected layer. The LocallyConnected layer words as a Dense layer connected to each of kernel_size time_steps (1 in this case). from tensorflow import keras from tensorflow.keras.layers

How to apply a different dense layer for each timestep in Keras

风格不统一 提交于 2021-01-29 02:21:30
问题 I know that applying a TimeDistributed(Dense) applies the same dense layer over all the timesteps but I wanted to know how to apply different dense layers for each timestep. The number of timesteps is not variable. P.S.: I have seen the following link and can't seem to find an answer 回答1: You can use a LocallyConnected layer. The LocallyConnected layer words as a Dense layer connected to each of kernel_size time_steps (1 in this case). from tensorflow import keras from tensorflow.keras.layers