tf.keras

How do you apply layer normalization in an RNN using tf.keras?

谁都会走 提交于 2020-06-25 03:49:08
问题 I would like to apply layer normalization to a recurrent neural network using tf.keras. In TensorFlow 2.0, there is a LayerNormalization class in tf.layers.experimental , but it's unclear how to use it within a recurrent layer like LSTM , at each time step (as it was designed to be used). Should I create a custom cell, or is there a simpler way? For example, applying dropout at each time step is as easy as setting the recurrent_dropout argument when creating an LSTM layer, but there is no

WARNING:tensorflow:sample_weight modes were coerced from … to ['…']

心已入冬 提交于 2020-06-24 04:58:07
问题 Training an image classifier using .fit_generator() or .fit() and passing a dictionary to class_weight= as an argument. I never got errors in TF1.x but in 2.1 I get the following output when starting training: WARNING:tensorflow:sample_weight modes were coerced from ... to ['...'] What does it mean to coerce something from ... to ['...'] ? The source for this warning on tensorflow 's repo is here, comments placed are: Attempt to coerce sample_weight_modes to the target structure. This

WARNING:tensorflow:sample_weight modes were coerced from … to ['…']

筅森魡賤 提交于 2020-06-24 04:58:03
问题 Training an image classifier using .fit_generator() or .fit() and passing a dictionary to class_weight= as an argument. I never got errors in TF1.x but in 2.1 I get the following output when starting training: WARNING:tensorflow:sample_weight modes were coerced from ... to ['...'] What does it mean to coerce something from ... to ['...'] ? The source for this warning on tensorflow 's repo is here, comments placed are: Attempt to coerce sample_weight_modes to the target structure. This

What are _get_hyper and _set_hyper in TensorFlow optimizers?

▼魔方 西西 提交于 2020-06-16 04:18:22
问题 I see it in __init__ of e.g. Adam optimizer: self._set_hyper('beta_1', beta_1) . There are also _get_hyper and _serialize_hyperparameter throughout the code. I don't see these in Keras optimizers - are they optional? When should or shouldn't they be used when creating custom optimizers? 回答1: They enable setting and getting Python literals ( int , str , etc), callables , and tensors. Usage is for convenience and consistency : anything set via _set_hyper can be retrieved via _get_hyper ,

Keras: Custom loss function with training data not directly related to model

走远了吗. 提交于 2020-06-09 02:09:23
问题 I am trying to convert my CNN written with tensorflow layers to use the keras api in tensorflow (I am using the keras api provided by TF 1.x), and am having issue writing a custom loss function, to train the model. According to this guide, when defining a loss function it expects the arguments (y_true, y_pred) https://www.tensorflow.org/guide/keras/train_and_evaluate#custom_losses def basic_loss_function(y_true, y_pred): return ... However, in every example I have seen, y_true is somehow

Keras: Custom loss function with training data not directly related to model

浪尽此生 提交于 2020-06-09 02:09:22
问题 I am trying to convert my CNN written with tensorflow layers to use the keras api in tensorflow (I am using the keras api provided by TF 1.x), and am having issue writing a custom loss function, to train the model. According to this guide, when defining a loss function it expects the arguments (y_true, y_pred) https://www.tensorflow.org/guide/keras/train_and_evaluate#custom_losses def basic_loss_function(y_true, y_pred): return ... However, in every example I have seen, y_true is somehow

Loading a model Raise ValueError Unknown loss function

时间秒杀一切 提交于 2020-06-01 06:50:05
问题 this is the code after i try to save and load my model: model.save('path_to_my_model.h5') del model model = tf.keras.models.load_model('path_to_my_model.h5', custom_objects={'Wraparound2D': Wraparound2D}) import tensorflow.keras.backend as K inp = model.input # input placeholder outputs = [layer.output for layer in model.layers] # all layer outputs functor = K.function(inp, outputs) # evaluation function layer_outs = functor([X_test, 1.]) # Plot activations of different neurons in different

In tensorflow, for custom layers that need arguments at instantialion, does the get_config method need overriding?

别说谁变了你拦得住时间么 提交于 2020-06-01 05:53:08
问题 Ubuntu - 20.04, Tensorflow - 2.2.0, Tensorboard - 2.2.1 I have read that one needs to reimplement the config method in order for a custom layer to be serializable. I have a custom layer that accepts arguments in its __init__ . It uses another custom layer and that consumes arguments in its __init__ as well. I can: Without Tensorboard callbacks: Use them in a model both in eager model and graph form Run tf.saved_model.save and it executes without a glich Load the thus saved model using tf

What is the connections between two stacked LSTM layers?

回眸只為那壹抹淺笑 提交于 2020-06-01 05:12:17
问题 The question is like this one What's the input of each LSTM layer in a stacked LSTM network?, but more into implementing details. For simplicity how about 4 units and 2 units structures like the following model.add(LSTM(4, input_shape=input_shape, return_sequences=True)) model.add(LSTM(2,input_shape=input_shape)) So I know the output of LSTM_1 is 4 length but how do the next 2 units handle these 4 inputs, are they fully connected to the next layer of nodes? I guess they are fully connected

'NoneType' object has no attribute '_inbound_nodes' error

。_饼干妹妹 提交于 2020-05-30 08:03:17
问题 I have to take the output of last conv layer of EfficientNet and then calculate H = wT*x+b. My w is [49,49]. After that I have to apply softmax on H and then do elementwise multiplication Xì = Hi*Xi. This is my code: common_input = layers.Input(shape=(224, 224, 3)) x=model0(common_input) #model0 terminate with last conv layer of EfficientNet (7,7,1280) x = layers.BatchNormalization()(x) W = tf.Variable(tf.random_normal([49,49], seed=0), name='weight') b = tf.Variable(tf.random_normal([49],