How to properly implement custom squash function in TF2.0 (custom layer or other)

I'm trying to implement a simple capsnet model in TF2.0. So far, I have added a few conv2d layers, and a reshape layer, but I need to add a squash function now. The issue is that tf.norm() will...

How to graph tf.keras model in Tensorflow-2.0?

I upgraded to Tensorflow 2.0 and there is no tf.summary.FileWriter("tf_graphs", sess.graph). I was looking through some other StackOverflow questions on this and they said to use...

Tensorflow can't use GPU. tf.test.is_gpu_available() show GPU but cannot use

I have Ubuntu 18.04. Python 3.7.3, Tensorflow 2.0.0 here's my cuda version: nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2017 NVIDIA Corporation Built on...

Tensorflow 2: how to switch execution from GPU to CPU and back?

In tensorflow 1.X with standalone keras 2.X, I used to switch between training on GPU, and running inference on CPU (much faster for some reason for my RNN models) with the following...

TimeDistributed of a KerasLayer in Tensorflow 2.0

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,...

ModelCheckpoint monitoring values when the model has multiple outputs

My model has two outputs, I want to monitor one to save my model. Below is part of my code. The version of TensorFlow is 2.0 model =...

Cannot import tensorflow_probability

When I try to import tensorflow_probability, I get this error: Traceback (most recent call last): File "PATH", line 1, in <module> import tensorflow_probability File "PATH", line 75, in...

Failed copying input tensor from CPU to GPU in order to run GatherVe: Dst tensor is not initialized. [Op:GatherV2]

from random import sample index=sample(range(0, len(result)), len(result)//5*4) description_train=[child[0] for i, child in enumerate(result) if i in index] ipc_train=[child[1] for...

Using learning rate schedule and learning rate warmup with TensorFlow2

I have to use learning rate warmup where you start training a VGG-19 CNN for CIFAR-10 with warmup from a learning rate of 0.00001 to 0.1 over the first 10000 iterations (or, approximately 13...

Modify code to be compatible on TensorFlow 2.3.0 (keras)

I got a tool that runs on TF1, but when I installed TF2 it stopped running because changes in the TF version. I need you help to update the code so that it will run on TF2. The code is is...

TF2 Object Detection API: model_main_tf2.py - validation loss?

I have been trying to train an object detection model for past 2 months and have finally succeeded by following this tutorial. Here is my colab which contains all my work. The problem is, the...

How to do atrous convolution in tensorflow 2 (tf.keras)

I am trying to convert some code from tensorflow 1.x to tensorflow 2.x. It's been going well so far, but I'm stuck on atrous convolution. Unlike other layers, there doesn't seem to be a...

How to save TextVectorization to disk in tensorflow?

from tensorflow.keras.layers.experimental.preprocessing import TextVectorization text_dataset = tf.data.Dataset.from_tensor_slices(text_clean) vectorizer = TextVectorization(max_tokens=100000,...

Can't install Tensorflow 2.3 on Raspberry Pi 4

I can't currently install TensorFlow 2.3 on a Raspberry Pi 4. Unfortunately, the pip doesn't return any TensorFlow version: pip install tensorflow== Looking in indexes: https://pypi.org/simple,...

PyTorch equivalent to tf.nn.softmax_cross_entropy_with_logits and tf.nn.sigmoid_cross_entropy_with_logits

I found the post here. Here, we try to find an equivalence of tf.nn.softmax_cross_entropy_with_logits in PyTorch. The answer is still confusing to me. Here is the Tensorflow 2 code import...

How to get the labels from tensorflow dataset

ds_test = tf.data.experimental.make_csv_dataset( file_pattern = "./dfj_test/part-*.csv.gz", batch_size=batch_size, num_epochs=1, #column_names=use_cols, label_name='label_id', ...

How to get tensorflow-gpu v2 working on Windows with NVidia GPU

What are the steps to get tensorflow-gpu 2.x Python package working on Windows with an NVidia GPU? I.e. how can I get rid of Could not find 'cudart64_101.dll' and then Could not find 'cudnn64_7.dll'?

How to properly use from_logits in keras loss function for binary classification?

Here is a sample neural net using tensorflow, x = tf.keras.layers.Input((None,)) x = tf.keras.layers.Dense(100)(x) x1 = tf.keras.layers.Dense(1)(x) model = tf.keras.Model(inputs=x,...

ModuleNotFoundError: No module named 'tensorflow_core.estimator' for tensorflow 2.1.0

When using tensorflow, I have the following error messages ERROR:root:Internal Python error in the inspect module. Below is the traceback from this internal error.' File "<frozen...

Tensorflow2 Object Detection Counting API for tutorial

I've racked my brain at customizing the TensorFlow object detection using webcam tutorial to count how many objects are detected from each classification. I trained my custom detection model using...

How to convert a channel first Keras model to channel last model?

I have a pre-trained Keras model (in h5 format) where all the layers operate on channel first data format. I want to convert this model to operate on the channel's last data format (the default...

How to get samples per class for TensorFlow Dataset

I am using dataset from TensorFlow datasets. Is there an easy way to access number of samples for each class in dataset? I was searching through keras api, and I did not found any ready to use...

How to clear Colab Tensorflow TPU memory

I am executing model for several folds. After each fold I want to clear the TPU memory so that I don't get OOM error. Full trace of the current error. ResourceExhaustedError ...

Keras Error: "Optimization loop failed: Cancelled: Operation was cancelled" When Calling predict_on_batch

I had some older working code that used keras. I recently dusted it off and tried to use it but with current versions of keras/tensorflow. I am getting a warning/error when calling...

TensorFlow 2.5.0 incompatibility with NumPy 1.21+? (2021-10-05)

To everyone who stumbles upon this: I was recently doing image classification (fit a CNN onto some labeled data) and I wanted to do data augmentation using keras's modules. However, I get thrown...

How can I handle the error "certificate verify failed: certificate has expired" in TensorFlow?

I'm just starting to create an image classification program in Python with TensorFlow using the CIFAR10 dataset, following this tutorial. Here is my code so far: import tensorflow as tf from...

How to print Keras tensor values?

I want to print the state values of LSTM layer. class CustomCallback(keras.callbacks.Callback): def on_epoch_end(self, epoch, logs=None): encoder_outputs, state_h, state_c =...

Get values from Tensor using argmax

I have a Tensor of shape (60, 128, 30000). I want to get the value of the argmax of the 30000 dimension (axis=2). This code is an example: tensor = tf.random.uniform((60, 128, 30000)) # shape...

How to plot learning curves for each trial using the keras-tuner

I am using keras tuner for model selection for my neural network model for a regression task, I would like to plot the learning curves for loss and validation loss for each iteration of the random...

Inference using saved model in Tensorflow 2: how to control in/output?

Adapting my code from TF1 to TF2.6 I run into trouble. I am trying to add some custom layers to an inception resnet, save the model, and then load and run it. from tensorflow.keras.layers import...