tensorflow2.0

Cannot generate random ints inside TensorFlow2.0 "call" function

Cannot generate random ints inside TensorFlow2.0 "call" function Question: I am trying to implement a custom dropout layer. In this dropout layer I want to generate a random number and turn on/off that output. The idea is simple and I thought the implementation would be too. I have tried using the regular ‘random’ python function, …

Total answers: 1

Tensorflow 2.13.1, no matching distribution found for tensorflow-text 2.13.0

Tensorflow 2.13.1, no matching distribution found for tensorflow-text 2.13.0 Question: I am trying to install the latest Tensorflow models 2.13.1 (pip install tf-models-official==2.13.1), with Python 3.11. There seems to be an issue with Cython and PyYAML not playing nice together since last week in Tensorflow models 2.13.0, so it won’t install. But 2.13.1 is giving …

Total answers: 2

Problems with numpy in Tensorflow

Problems with numpy in Tensorflow Question: from tensorflow import keras import matplotlib.pyplot as plt import numpy as np data = keras.datasets.boston_housing (x_train, x_test), (y_train, y_test) = data.load_data() model = keras.Sequential([ keras.layers.InputLayer(13), keras.layers.Dense(3, activation="relu"), keras.layers.Dense(1, activation="sigmoid") ]) model.compile(optimizer="adam", loss="sparse_categorical_crossentropy", metrics="accuracy") model.fit(x_train, y_train, epochs=10) predict = model.predict(x_test) for i in range(10): plt.grid(False) plt.imshow(x_test[i], cmap=plt.cm.binary) plt.suptitle("Actual: " + …

Total answers: 2

tf.keras.utils.get_file error: TypeError: '<' not supported between instances of 'int' and 'NoneType'

tf.keras.utils.get_file error: TypeError: '<' not supported between instances of 'int' and 'NoneType' Question: everyone, Recently I start to program with tensorflow 2.10.0, have the following codes in my ipynb file (Jupyter Notebook file): if not data_dir.exists(): tf.keras.utils.get_file(‘free-spoken-digit-dataset-master.zip’,origin="https://codeload.github.com/Jakobovski/free-spoken-digit-dataset/zip/refs/heads/master",extract=True,cache_dir=’.’,cache_subdir=’data’) I want to download the file free-spoken-digit-dataset-master.zip from the URL https://codeload.github.com/Jakobovski/free-spoken-digit-dataset/zip/refs/heads/master, after running the codes the following error …

Total answers: 2

Which metrics are printed (train or validation) when validation_split and validation_data is not specified in the keras model.fit function?

Which metrics are printed (train or validation) when validation_split and validation_data is not specified in the keras model.fit function? Question: I have a TF neural network and I am using the tf.data API to create the dataset using a generator. I am not passing validation_split and validation_data into the model.fit() function of keras. The default …

Total answers: 1

How do I return just one element from this output?

How do I return just one element from this output? Question: I am using TensorFlow in Python. When making a prediction with my model, here is my input: UberLyft_model.predict(my_UberLyft_encoded) I get this output: 1/1 [==============================] – 0s 53ms/step array([[16.11945]], dtype=float32) But I simply want this output: 16.11945 Asked By: Swifty || Source Answers: Try prediction …

Total answers: 1

Weird behaviour in tensorflow metric

Weird behaviour in tensorflow metric Question: I have created a tensorflow metric as seen below: def AttackAcc(y_true, y_pred): r = tf.random.uniform(shape=(), minval=0, maxval=11, dtype=tf.int32) if tf.math.greater(r,tf.constant(5) ): return tf.math.equal( tf.constant(0.6) , tf.constant(0.2) ) else: return tf.math.equal( tf.constant(0.6) , tf.constant(0.6) ) The metric is added to the model.compile as : metrics=[AttackAcc] This should return 0 half …

Total answers: 1

Tensorflow / CUDA: GPU not detected

Tensorflow / CUDA: GPU not detected Question: I have two Windows 11 laptops with NVIDIA GeForce RTX 3060 GPUs, which I want to run Tensorflow on. If that matters, both laptops are Lenovo Legion 5 laptops with "GPU Working Mode" set to "Hybrid-Auto Mode". The first laptop has the following setup: Python 3.10.7 Tensorflow 2.9.1 …

Total answers: 1

How to combine a masked loss with tensorflow2 TimeSeriesGenerator

How to combine a masked loss with tensorflow2 TimeSeriesGenerator Question: We are trying to use a convolutional LSTM to predict the values of an image given the past 7 timesteps. We have used the tensorflow2 TimeSeriesGenerator method to create our time series data: train_gen = TimeseriesGenerator( data, data, length=7, batch_size=32, shuffle=False ) Every image (timestep) …

Total answers: 1

Selective meshgrid in Tensorflow

Selective meshgrid in Tensorflow Question: Given the following code: import tensorflow as tf def combine(x, y): xx, yy = tf.meshgrid(x, y, indexing=’ij’) combo = tf.stack([tf.reshape(xx, [-1]), tf.reshape(yy, [-1])], axis=1) print(combo) x = tf.constant([11, 0, 7, 1]) combine(x, x) I want to clean combo vector in order to obtain the following tf vector [(11, 0), (11, …

Total answers: 1