tensorflow2.0

tf.keras plot_model: add_node() received a non node class object

狂风中的少年 提交于 2020-05-16 05:53:10
问题 I'm getting back into python and have been trying out some stuff with tensorflow and keras. I wanted to use the plot_model function and after sorting out some graphviz issues I am now getting this error - TypeError: add_node() received a non node class object: I've tried to find an answer myself but have come up short, as the only answer I found with this error didn't seem to be to do with tf. Any suggestions or alternative ideas would be greatly appreciated. Here's the code and error message

TimeDistributed of a KerasLayer in Tensorflow 2.0

醉酒当歌 提交于 2020-05-15 19:22:05
问题 I'm trying to build a CNN + RNN using a pre-trained model from tensorflow-hub: base_model = hub.KerasLayer('https://tfhub.dev/google/imagenet/resnet_v2_50/feature_vector/4', input_shape=(244, 244, 3) base_model.trainable = False model = Sequential() model.add(TimeDistributed(base_model, input_shape=(15, 244, 244, 3))) model.add(LSTM(512)) model.add(Dense(256, activation='relu')) model.add(Dense(3, activation='softmax')) adam = Adam(learning_rate=learning_rate) model.compile(loss='categorical

TimeDistributed of a KerasLayer in Tensorflow 2.0

こ雲淡風輕ζ 提交于 2020-05-15 19:21:08
问题 I'm trying to build a CNN + RNN using a pre-trained model from tensorflow-hub: base_model = hub.KerasLayer('https://tfhub.dev/google/imagenet/resnet_v2_50/feature_vector/4', input_shape=(244, 244, 3) base_model.trainable = False model = Sequential() model.add(TimeDistributed(base_model, input_shape=(15, 244, 244, 3))) model.add(LSTM(512)) model.add(Dense(256, activation='relu')) model.add(Dense(3, activation='softmax')) adam = Adam(learning_rate=learning_rate) model.compile(loss='categorical

Can I access what was once `tf.get_global_step()` from within a custom Keras layer?

醉酒当歌 提交于 2020-05-15 08:42:09
问题 I'm implementing a custom Layer with the Keras API (working with TF2.0-beta ). I want to use the epoch number in my calculation in order to decay a parameter over time (meaning - in the call() method). I'm used to tf.get_global_step() but understand that TF deprecated all global scopes, and definitely for a good reason. If I had the model instance, I could use model.optimizer.iterations , but I'm not sure how I get the instance of my parent model when I'm implementing a Layer. Do I have any

tf-models: official.vision.detection Mask-RCNN Invalid argument: indices[1,63] = [1, -1] does not index into param shape [2,100,112,112]

独自空忆成欢 提交于 2020-05-15 04:15:07
问题 I am trying to train a Mask RCNN model based on the official MaskRCNN model present here: tensorflow/models. Below are the steps I followed: Created a tfrecord for training and validation. I have checked encoding and decoding of the tfrecords, it is working fine. Set up the config file as below: # my_maskrcnn.yaml train: train_file_pattern: "data/<dataset_name>/train/tfrecords/train.tfrecord-*" batch_size: 2 eval: eval_file_pattern: "data/<data_set_name>/val/tfrecords/val.tfrecord-*" batch

NotImplementedError: Cannot convert a symbolic Tensor (truediv_2:0) to a numpy array

南笙酒味 提交于 2020-05-14 13:40:06
问题 If you execute the following TensorFlow 2.1 code import tensorflow as tf import tensorflow_probability as tfp tf.config.experimental_run_functions_eagerly(True) def get_mnist_data(normalize=True, categorize=True): img_rows, img_cols = 28, 28 (x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data() if tf.keras.backend.image_data_format() == 'channels_first': x_train = x_train.reshape(x_train.shape[0], 1, img_rows, img_cols) x_test = x_test.reshape(x_test.shape[0], 1, img_rows

Tensorflow Keras modify model variable from callback

泪湿孤枕 提交于 2020-05-13 14:51:06
问题 I am trying to modify a non-trainable model variable from a callback on beginning of each epoch. Essentially I would like to have a mechanism similar to the learning rate scheduler (which has built in infrastructure in TF) but applicable to an arbitrary model variable. The code below is a minimum example to show the concept. I am trying to modify the decay variable but it does not work. Apparently the initial value of the variable (1.0) is treated as a constant and folded by the graph and

How to train a parameter outside the model?

喜你入骨 提交于 2020-04-30 07:19:31
问题 I am implementing the following architecture in Tensorflow 2.0 Dual Encoder LSTM C and R are sentences encoded into a fixed dimension by the two LSTM's. Then they are passed through a function sigmoid(CMR). We can assume that R and C are both 256 dimensional matrices and M is a 256 * 256 matrix. The matrix M is learned during training. Since I want to train M, I declared M = tf.Variable(shape,trainable = True). But after fitting the model, the values of M are still not changing. How to tell

How to train a parameter outside the model?

*爱你&永不变心* 提交于 2020-04-30 07:18:47
问题 I am implementing the following architecture in Tensorflow 2.0 Dual Encoder LSTM C and R are sentences encoded into a fixed dimension by the two LSTM's. Then they are passed through a function sigmoid(CMR). We can assume that R and C are both 256 dimensional matrices and M is a 256 * 256 matrix. The matrix M is learned during training. Since I want to train M, I declared M = tf.Variable(shape,trainable = True). But after fitting the model, the values of M are still not changing. How to tell

How can I write some layer's logic based on the current epoch or step of epoch?

谁说胖子不能爱 提交于 2020-04-30 06:31:52
问题 The Keras' documentation describes here how to write a custom layer by inheriting from the Layer class. Now, I have another custom layer CustomLayer , from which I want to inherit. Let's call my new custom layer CustomLayer2 . I guess that the process of inheriting, even though I will not be inheriting from Layer but from CustomLayer , will be the same described in the linked documentation, but I will also inherit the custom functionality of CustomLayer . Anyway, inside this custom layer