Category : tf.keras

I was learning making custom layers in tensor flow but could not find out how to add trainable weights for example class Linear(layers.Layer): def __init__(self, units = 32, **kwargs): super().__init__(kwargs) self.units = units def build(self, input_shape): self.layer = layers.Dense(self.units, trainable= True) super().build(input_shape) def call(self, inputs): return self.layer(inputs) Now if I do linear_layer = Linear(8) x ..

Read more

How can I make a stateful custom layer, a layer that has a state whose value is updated at each batch I tried something Like this. class customLayer(Layer): … def build(self, input_shape): self.state = tf.Variable(…,trainable=False) def call(self, inputs): … K.update(self.state, new_state) return … the problem with this is that it can’t calculate the gradients of ..

Read more

I am training my models and I have written some Keras custom callbacks, which I wrap in a tf.keras.callbacks.CallbackList and call using the .on_train/epoch/batch_begin/end() functions. These functions take two arguments, epoch/batch and logs, which is a dictionary containing some ad hoc values that you would set, as far as I understand, using the high level ..

Read more

belos is my code to ensure that the folder has images, but tf.keras.preprocessing.image_dataset_from_directory returns no images found. What did I do wrong? Thanks. DATASET_PATH = pathlib.Path(‘C:UsersxxxDocumentsimages’) image_count = len(list(DATASET_PATH.glob(‘.*.jpg’))) print(image_count) output = 2715 batch_size = 4 img_height = 32 img_width = 32 train_ds = tf.keras.preprocessing.image_dataset_from_directory( DATASET_PATH.name, validation_split=0.8, subset="training", seed=123, image_size=(img_height, img_width), batch_size=batch_size) output: Found 0 ..

Read more

I am following this code on GitHub. Its aim is to get a Monte Carlo Dropout for a LSTM model in order to produce confidence intervals. The code runs fine until this point, and I believe it’s because I’m on a much more recent version of Tensorflow and Keras. predict_stochastic = K.function([model.layers[0].input, K.learning_phase()], [model.layers[-1].output]) How ..

Read more