keras

How to train keras model using Google Cloud TPU

孤街浪徒 提交于 2021-02-07 12:11:33
问题 Theoretically, we are able to train Tensorflow backed Keras model on any platform that supports Tensorflow. However, I can't seem to find any info on how to do it in Google's documentation https://cloud.google.com/tpu/docs/. 回答1: We have an example in the TPU repository here: https://github.com/tensorflow/tpu/blob/master/models/experimental/cifar_keras/cifar_keras.py 来源: https://stackoverflow.com/questions/48771723/how-to-train-keras-model-using-google-cloud-tpu

Memory leak with TensorFlow

蹲街弑〆低调 提交于 2021-02-07 11:24:46
问题 I have a memory leak with TensorFlow. I refered to Tensorflow : Memory leak even while closing Session? to address my issue, and I followed the advices of the answer, that seemed to have solved the problem. However it does not work here. In order to recreate the memory leak, I have created a simple example. First, I use this function (that I got here : How to get current CPU and RAM usage in Python?) to check the memory use of the python process : def memory(): import os import psutil pid =

Keras Lambda Layer for matrix vector multiplication

纵然是瞬间 提交于 2021-02-07 10:30:54
问题 I am trying to have a lambda layer in keras that performs a vector matrix multiplication, before passing it to another layer. The matrix is fixed (I don't want to learn it). Code below: model.add(Dropout(0.1)) model.add(Lambda(lambda x: x.dot(A))) model.add(Dense(output_shape, activation='softmax')) model.compile(<stuff here>)} A is the fixed matrix, and I want to do x.dot(A) WHen I run this, I get the following error: 'Tensor' object has no attribute 'dot' Same Error when I replace dot with

Keras Lambda Layer for matrix vector multiplication

江枫思渺然 提交于 2021-02-07 10:30:00
问题 I am trying to have a lambda layer in keras that performs a vector matrix multiplication, before passing it to another layer. The matrix is fixed (I don't want to learn it). Code below: model.add(Dropout(0.1)) model.add(Lambda(lambda x: x.dot(A))) model.add(Dense(output_shape, activation='softmax')) model.compile(<stuff here>)} A is the fixed matrix, and I want to do x.dot(A) WHen I run this, I get the following error: 'Tensor' object has no attribute 'dot' Same Error when I replace dot with

Bi-LSTM Attention model in Keras

我怕爱的太早我们不能终老 提交于 2021-02-07 09:15:42
问题 I am trying to make an attention model with Bi-LSTM using word embeddings. I came across How to add an attention mechanism in keras?, https://github.com/philipperemy/keras-attention-mechanism/blob/master/attention_lstm.py and https://github.com/keras-team/keras/issues/4962. However, I am confused about the implementation of Attention-Based Bidirectional Long Short-Term Memory Networks for Relation Classification . So, _input = Input(shape=[max_length], dtype='int32') # get the embedding layer

Use of Keras Sparse Categorical Crossentropy for pixel-wise multi-class classification

主宰稳场 提交于 2021-02-07 08:45:29
问题 I'll start by disclosing that I'm a machine learning and Keras novice and don't know much beyond general CNN binary classifiers. I'm trying to perform pixelwise multi-class classification using a U-Net architecture (TF backend) on many 256x256 images. In other words, I input a 256x256 image, and I want it to output a 256x256 "mask" (or label image) where the values are integers from 0-30 (each integer represents a unique class). I'm training on 2 1080Ti NVIDIA GPUs. When I attempt to perform

Use of Keras Sparse Categorical Crossentropy for pixel-wise multi-class classification

删除回忆录丶 提交于 2021-02-07 08:44:35
问题 I'll start by disclosing that I'm a machine learning and Keras novice and don't know much beyond general CNN binary classifiers. I'm trying to perform pixelwise multi-class classification using a U-Net architecture (TF backend) on many 256x256 images. In other words, I input a 256x256 image, and I want it to output a 256x256 "mask" (or label image) where the values are integers from 0-30 (each integer represents a unique class). I'm training on 2 1080Ti NVIDIA GPUs. When I attempt to perform

Setting the hidden state for each minibatch with different hidden sizes and multiple LSTM layers in Keras

天大地大妈咪最大 提交于 2021-02-07 08:02:21
问题 I created an LSTM using Keras with TensorFlow as backend. Before a minibatch with a num_step of 96 is given to the training, the hidden state of the LSTM is set to true values of a previous time step. First the parameters and data: batch_size = 10 num_steps = 96 num_input = num_output = 2 hidden_size = 8 X_train = np.array(X_train).reshape(-1, num_steps, num_input) Y_train = np.array(Y_train).reshape(-1, num_steps, num_output) X_test = np.array(X_test).reshape(-1, num_steps, num_input) Y_test

Access deprecated attribute “validation_data” in tf.keras.callbacks.Callback

倖福魔咒の 提交于 2021-02-07 07:27:18
问题 I decided to switch from keras to tf.keras (as recommended here). Therefore I installed tf.__version__=2.0.0 and tf.keras.__version__=2.2.4-tf . In an older version of my code (using some older Tensorflow version tf.__version__=1.x.x ) I used a callback to compute custom metrics on the entire validation data at the end of each epoch. The idea to do so was taken from here. However, it seems as if the "validation_data" attribute is deprecated so that the following code is not working any longer

Confusion about keras Model: __call__ vs. call vs. predict methods

流过昼夜 提交于 2021-02-07 07:21:34
问题 I have realized that I do not quite understand the difference between calling either the __call__ , call , or predict method of a Keras' model. For example, we have a trained keras model. After calling the code: # After training. y_pred_1 = model(X_new) y_pred_2 = model.call(X_new) y_pred_3 = model.predict(X_new) I expected that y_pred_1 , y_pred_2 , and y_pred_3 are all the same. But it turned out that they are not the same. Could you please explain to me the difference? 回答1: Just to