tf.keras

Can't add random noise to weights inside a Keras Layer

Can't add random noise to weights inside a Keras Layer Question: I am trying to add a random noise during forward pass to a convolutional layer in Keras. I wrote a wrapper class where it would add noise to the weights before computing convolution. Any addition or modifications to self.weights has no effect to the …

Total answers: 1

TensorFlow results are not reproducible despite using tf.random.set_seed

TensorFlow results are not reproducible despite using tf.random.set_seed Question: According to a tutorial on Tensorflow I am following, the following code is supposed to give reproducible results, so one can check if the exercise is done correctly. Tensorflow version is 2.11.0. import tensorflow as tf import numpy as np class MyDenseLayer(tf.keras.layers.Layer): def __init__(self, n_output_nodes): super(MyDenseLayer, …

Total answers: 1

Attribute error in PPO algorithm for Cartpole gym environment

Attribute error in PPO algorithm for Cartpole gym environment Question: I’m trying to run the code from here (Github link on this page): https://keras.io/examples/rl/ppo_cartpole/ I’m getting an attribute error in the training section from observation = observation.reshape(1,-1) which says "’tuple’ object has no attribute ‘reshape’". It seems that observation is currently env.reset() which is a …

Total answers: 1

I am having a value error in my keras model, calling 'model.fit' gives a value error. i keep getting value error error when i try to fit the model

I am having a value error in my keras model, calling 'model.fit' gives a value error. i keep getting value error error when i try to fit the model Question: X=np.array([-7.0,-4.0,-1.0,2.0,5.0,8.0,11.0,14.0]) y=np.array([3.0,6.0,9.0,12.0,15.0,18.0,21.0,24.0]) X=tf.cast(tf.constant(X), dtype=tf.float32) y=tf.cast(tf.constant(y), dtype=tf.float32) tf.random.set_seed(42) model = tf.keras.Sequential([ tf.keras.layers.Dense(1) ]) model.compile(loss=tf.keras.losses.mae, optimizer=tf.keras.optimizers.SGD(), metrics=["mae"]) model.fit(X, y, epochs=5) `————————————————————————— ValueError Traceback (most recent call last) …

Total answers: 1

How can I put new input in the middle of the layers in Keras?

How can I put new input in the middle of the layers in Keras? Question: This model is what I want to implement. When the teacher model gets a sentence, it will output values that give more weight to important words for classification (e.g When the sentence is "I want to slaughter those people", then …

Total answers: 1

keras: ValueError: Failed to find data adapter that can handle input

keras: ValueError: Failed to find data adapter that can handle input Question: I have a deep learning model that I’m trying to test with simple input. On this line: history = model.fit(X_train, y_train, epochs=10, validation_data=(X_valid, y_valid)) I am getting this error: Traceback (most recent call last): File "/usr/lib64/python3.6/contextlib.py", line 99, in __exit__ self.gen.throw(type, value, traceback) …

Total answers: 1

create tensorflow dataset from list_files

create tensorflow dataset from list_files Question: I am trying to create tensroflow dataset : path_imgs = (‘./images/train/*.jpg’) path_masks =(‘./masks/train/*.jpg’ images = tf.data.Dataset.list_files(path_imgs, shuffle=False) masks = tf.data.Dataset.list_files(path_masks, shuffle=False) dataset = tf.data.Dataset.from_tensor_slices((tf.constant(path_imgs), tf.constant(path_masks))) and I am receiving: Unbatching a tensor is only supported for rank >= 1 Asked By: George || Source Answers: Try something like this: …

Total answers: 1

How to get shapes of all the layers in a model?

How to get shapes of all the layers in a model? Question: Consider the following model def create_model(): x_1=tf.Variable(24) bias_initializer = tf.keras.initializers.HeNormal() model = Sequential() model.add(Conv2D(64, (5, 5), input_shape=(28,28,1),activation="relu", name=’conv2d_1′, use_bias=True,bias_initializer=bias_initializer)) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Conv2D(32, (5, 5), activation="relu",name=’conv2d_2′, use_bias=True,bias_initializer=bias_initializer)) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Flatten()) model.add(Dense(120, name=’dense_1′,activation="relu", use_bias=True,bias_initializer=bias_initializer),) model.add(Dense(10, name=’dense_2′, activation="softmax", use_bias=True,bias_initializer=bias_initializer),) Is there any way I can get …

Total answers: 1

How to stack tensors (from images) to train a CNN?

How to stack tensors (from images) to train a CNN? Question: I have converted images to tensors. How should I stack them to train for a Convolutional Neural Network in keras. mask_tensor = tf.Variable([]) for img in mask_img: image = tf.io.read_file(img) tensor = tf.io.decode_jpeg(image, channels=3) tensor = tf.image.resize(tensor, [128,128]) if mask_tensor.shape == 0: mask_tensor = …

Total answers: 1