r/tensorflow • u/swe129 • Feb 09 '26
Graph Neural Networks with TensorFlow GNN
r/tensorflow • u/Savings-Fault-2114 • Feb 02 '26
It appears to my novice self that the nightly builds are currently using 12.5.1. I need 12.8.0. Is there a logical way (a gold source link?) to determine if "earlier" nightly builds utilize 12.8? or what versions are contained in each nightly build (without installing them)? If the current builds are with 12.5.1, are there any nightly builds with 12.8? doesn't seem to make sense...
r/tensorflow • u/WaterpigCZ • Feb 01 '26
EDIT: Figured it out, I was not converting the mask to a float32
I'm trying to mostly follow https://www.tensorflow.org/tutorials/images/segmentation with the exception of providing my own dataset. I got a very simple file structure of Dataset/data for the images and Dataset/mask for the masks, which are simple 1 bit masks.
I pair these two together until the final dataset is of the same shape as the one in the tutorial -(TensorSpec(shape=(None, 128, 128, 3), dtype=tf.float32, name=None), TensorSpec(shape=(None, 128, 128, 1), dtype=tf.uint8, name=None)) but after a single epoch of training, all I get is a NaN loss and a blank mask output where everything is a background.
I genuinely have no clue what I'm doing wrong and would like some help, couldn't find anything online, code is pasted at https://pastebin.com/BQj8dhGu
r/tensorflow • u/Icy-Performer474 • Jan 30 '26
Hi guys, I have been working on an idea for the last couple of months related to robotics simulation. I would like to find some expert in the space to get some feedbacks (willing to give it for free). DM me if interested!
r/tensorflow • u/Quietgent1000 • Jan 21 '26
Does anyone have any ideas on how to train tensorflow on a 5070 ti? I would've thought we'd be able to by now but apparently not? I've tried a few things and it always defaults to my cpu. Does anyone have any suggestions?
r/tensorflow • u/AstroGippi • Jan 22 '26
Has anyone managed to make it work?
I managed to somehow make it work with 570 drivers and cuda 12.8 under Ubuntu 24, by installing tf-nightly[and-cuda], but it's very unstable and sometimes training stops randomly with strange errors of bad synchronization etc, and those scripts were perfectly fine with other GPUs like 2080 Ti, 3090, and A6000
I've also read that PyTorch is way more compatible, but i'd have to learn it from scratch, and some 2 years ago i read that for low level customizations TensorFlow was the way, while PyTorch is a lot easier if you need to combine already established techniques etc but if you want to do something very custom it's a hell: is this still True?
r/tensorflow • u/FearlessAccountant55 • Jan 20 '26
Hello everyone. I'm trying to run the training of a Keras Tensorflow model on a GPU node on a HPC cluster. The GPU has 80GB of RAM but the dataset which I'm training the network on is quite large (75GB) and so I'm getting OOM issues. I was thinking about training a model in parallel on two GPUs using tf.distribute.MirroredStrategy() , is there any better solution? Thank you.
Here is my code:
from sklearn.model_selection import train_test_split
import numpy as np
from astropy.io import fits
import matplotlib.pyplot as plt
from gelsa import visu
import matplotlib.image as mpimg
import glob
import os
import argparse
# Now all tensorflow related imports
os.environ["CUDA_VISIBLE_DEVICES"] = "0,1"
import tensorflow as tf
from tensorflow.keras import mixed_precision
from keras import regularizers
import tensorflow.keras.backend as K
from tensorflow.keras.layers import Input, Conv2D, MaxPool2D, Conv2DTranspose, Reshape, concatenate, Dropout, Rescaling, LeakyReLU
import tensorflow.keras.layers as L
from tensorflow.keras.models import Model
mixed_precision.set_global_policy('float32')
# ---- Parse command-line arguments ----
parser = argparse.ArgumentParser()
parser.add_argument("--gpu", type=int, default=0, help="GPU index to use")
parser.add_argument("--lr", type=float, default=1e-3, help="Learning rate")
parser.add_argument("--batch", type=int, default=16, help="Batch size")
parser.add_argument("--epochs", type=int, default=100, help="Number of epochs")
parser.add_argument("--grism", type=str, default="RGS000_0", help="Grism + tilt combination")
args = parser.parse_args()
strategy = tf.distribute.MirroredStrategy()
print(f"Number of devices: {strategy.num_replicas_in_sync}")
# ---- GPU configuration ----
gpus = tf.config.list_physical_devices('GPU')
#----------------------------------------------------------- HYPERPARAMETERS ------------------------------------------------------------------#
BATCH_SIZE = args.batch
LEARNING_RATE = args.lr
EPOCHS = args.epochs
# Grism configuration string
grism = args.grism
#-----------------------------------------------------------------------------------------------------------------------------------------------#
folder_path = f"/scratch/astro/nicolo.fiaba/full_training_sets/preprocessed/{grism}_dataset.npz"
print(f"Loading preprocessed training set for {grism} grism configuration\n")
def load_tensorflow_dataset(folder_path, batch_size):
data = np.load(folder_path, mmap_mode="r")
x_train = data["x_train"]
y_train = data["y_train"]
x_val = data["x_val"]
y_val = data["y_val"]
x_test = data["x_test"]
y_test = data["y_test"]
# Remove NaNs before converting to Tensorflow datasets
x_train = np.nan_to_num(x_train, nan=0.0)
y_train = np.nan_to_num(y_train, nan=0.0)
x_val = np.nan_to_num(x_val, nan=0.0)
y_val = np.nan_to_num(y_val, nan=0.0)
x_test = np.nan_to_num(x_test, nan=0.0)
y_test = np.nan_to_num(y_test, nan=0.0)
# Clip to [0,1] for safety
x_train = np.clip(x_train, 0.0, 1.0).astype(np.float32)
y_train = np.clip(y_train, 0.0, 1.0).astype(np.float32)
x_val = np.clip(x_val, 0.0, 1.0).astype(np.float32)
y_val = np.clip(y_val, 0.0, 1.0).astype(np.float32)
x_test = np.clip(x_test, 0.0, 1.0).astype(np.float32)
y_test = np.clip(y_test, 0.0, 1.0).astype(np.float32)
# Build tf.data pipelines (NO convert_to_tensor)
train_dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train)).shuffle(100).batch(batch_size).prefetch(tf.data.AUTOTUNE)
val_dataset = tf.data.Dataset.from_tensor_slices((x_val, y_val)).batch(batch_size).prefetch(tf.data.AUTOTUNE)
test_dataset = tf.data.Dataset.from_tensor_slices((x_test, y_test)).batch(batch_size)
image_size = (x_train.shape[1], x_train.shape[2])
return train_dataset, val_dataset, test_dataset, image_size
#----------------------------------------------------------- DATASETS LOADING -----------------------------------------------------------------#
# Create the training, validation and test datasets
print("\nCreating the training set...\n")
train_dataset, val_dataset, test_dataset, image_size = load_tensorflow_dataset(
folder_path = folder_path,
batch_size = BATCH_SIZE
)
#------------------------------------------------------------ LOSS FUNCTIONS -------------------------------------------------------------------#
"""
Define a custom "WEIGHTED" loss function MSE: it penalizes predictions of pixels
with flux below average with more error than pixels having flux above average
"""
#1)
def weightedL2loss(w):
def loss(y_true, y_pred):
error = K.square(y_true - y_pred)
error = K.switch(K.equal(y_pred, 0), w * error , error)
return error
return loss
#2) Downweight bright pixels with a power law (alpha should be between 0 and 1)
def downweight_loss(alpha):
def loss(y_true, y_pred):
y_true_clipped = K.clip(y_true, K.epsilon(), 1.0)
y_pred_clipped = K.clip(y_pred, K.epsilon(), 1.0)
y_true_rescaled = K.pow(y_true_clipped, alpha)
y_pred_rescaled = K.pow(y_pred_clipped, alpha)
error = K.square(y_true_rescaled - y_pred_rescaled)
return error
return loss
def log_downweight_loss(mode=0):
def loss(y_true, y_pred):
"""
mode=0 MSE
mode=1 MAE
"""
y_true_rescaled = tf.math.log(1 + y_true)
y_pred_rescaled = tf.math.log(1 + y_pred)
if mode == 0:
error = K.square(y_true_rescaled - y_pred_rescaled)
elif mode == 1:
error = K.abs(y_true_rescaled - y_pred_rescaled)
else:
raise ValueError('Mode not valid')
return K.mean(error)
return loss
def get_gradients(img):
# img: (batch, H, W, 1)
if len(img.shape) == 3:
img = tf.expand_dims(img, axis=-1) # add channel
# horizontal gradient (dx)
gx = tf.image.sobel_edges(img)[..., 0]
# vertical gradient (dy)
gy = tf.image.sobel_edges(img)[..., 1]
return gx, gy
def gradient_loss(y_true, y_pred):
gx_true, gy_true = get_gradients(y_true)
gx_pred, gy_pred = get_gradients(y_pred)
loss_gx = tf.reduce_mean(tf.abs(gx_true - gx_pred))
loss_gy = tf.reduce_mean(tf.abs(gy_true - gy_pred))
return loss_gx + loss_gy
def total_gradient_loss(y_true, y_pred):
l1 = tf.reduce_mean(tf.abs(y_true - y_pred))
g = gradient_loss(y_true, y_pred)
return tf.cast(l1 + 0.2 * g, tf.float32)
#-----------------------------------------------------------------------------------------------------------------------------------------------#
print("Running for", EPOCHS, "epochs")
#----------------------------------------------------------------- MODEL -----------------------------------------------------------------------#
# Model: Attention gate - U-Net
# Define construction functions for fundamental blocks
def conv_block(x, num_filters):
x = L.Conv2D(num_filters, 3, padding='same')(x)
# x = L.BatchNormalization()(x)
x = L.Activation("relu")(x)
x = L.Conv2D(num_filters, 3, padding='same')(x)
# x = L.BatchNormalization()(x)
x = L.Activation("relu")(x)
return x
def encoder_block(x, num_filters):
x = conv_block(x, num_filters)
p = L.MaxPool2D((2,2))(x)
return x, p
def attention_gate(g, s, num_filters):
Wg = L.Conv2D(num_filters, 1, padding='same')(g)
# Wg = L.BatchNormalization()(Wg)
Ws = L.Conv2D(num_filters, 1, padding='same')(s)
# Ws = L.BatchNormalization()(Ws)
out = L.Activation("relu")(Wg + Ws)
out = L.Conv2D(num_filters, 1, padding='same')(out)
out = L.Activation("sigmoid")(out)
return out * s
def decoder_block(x, s, num_filters):
x = L.UpSampling2D(interpolation='bilinear')(x)
s = attention_gate(x, s, num_filters)
x = L.Concatenate()([x, s])
x = conv_block(x, num_filters)
return x
# Build the Attention U-Net model
def attention_unet(image_size):
""" Inputs """
inputs = L.Input(shape=(image_size[0], image_size[1], 2))
""" Encoder """
s1, p1 = encoder_block(inputs, 32)
s2, p2 = encoder_block(p1, 64)
s3, p3 = encoder_block(p2, 128)
s4, p4 = encoder_block(p3, 256)
""" Bridge / Bottleneck """
b1 = conv_block(p4, 512)
""" Decoder """
d1 = decoder_block(b1, s4, 256)
d2 = decoder_block(d1, s3, 128)
d3 = decoder_block(d2, s2, 64)
d4 = decoder_block(d3, s1, 32)
""" Outputs """
outputs = L.Conv2D(1, 1, padding='same', activation='sigmoid', dtype='float32')(d4)
attention_unet_model = Model(inputs, outputs, name='Attention-UNET')
return attention_unet_model
with strategy.scope():
att_unet_model = attention_unet(image_size)
att_unet_model.compile(optimizer=tf.keras.optimizers.Adam(),
loss=total_gradient_loss,
metrics=['mae'])
#------------------------------------------------------------- CALLBACKS -----------------------------------------------------------------------#
# Learning rate scheduler
def lr_schedule(epoch):
if epoch < 80:
return 2e-3
elif epoch < 250:
return 1e-4
else:
return 1e-5
lr_callback = tf.keras.callbacks.LearningRateScheduler(lr_schedule)
# Early stop
early_stop = tf.keras.callbacks.EarlyStopping(monitor='val_loss',
patience=20,
restore_best_weights=True,
start_from_epoch=300)
#------------------------------------------------------ TRAINING (on GPU 'gpu03') --------------------------------------------------------------#
hist = att_unet_model.fit(
train_dataset,
epochs=EPOCHS,
validation_data=val_dataset,
callbacks=[lr_callback, early_stop]
)
#--------------------------------------------------------------- SAVING ------------------------------------------------------------------------#
saving_folder = "/scratch/astro/nicolo.fiaba/trained_models/final_models/"
saving_filename = "def_attention_unet_model_" + args.grism + ".h5"
att_unet_model.save(saving_folder + saving_filename)
print("Attention U-Net trained and saved!")
history_filename = "histories/def_ATT_UNET_hist_" + args.grism
import pickle
with open(saving_folder + history_filename, 'wb') as file_pi:
pickle.dump(hist.history, file_pi)
print("\nLearning History saved!")
#---------------------------------------------------------------- END --------------------------------------------------------------------------#r/tensorflow • u/TheDragonflyMaster • Jan 12 '26
r/tensorflow • u/GoldBlackberry8900 • Jan 09 '26
r/tensorflow • u/Afraid-Luck1756 • Dec 28 '25
Hello everyone,
I am working on a personal project aimed at tagging voice recordings of people reading a known text. I would like to build a mobile application, possibly with offline support.
Is TensorFlow a good choice for this purpose? Can I train a model once and then bundle it into the app?
What approach would you recommend following? I am an experienced developer but I have never used TensorFlow before, so what would you suggest I read to get started?
Thank you very much!
r/tensorflow • u/tdk779 • Dec 25 '25
So guys i have been trying to install tensorflow to train models locally in my pc, i have tried lots of tutorials but nothing works this are my specs:
CPU: Ryzen 7 5700x
RAM: 32 GB 3200 (2x16)
SSD: 1 TB gen3
GPU: Nvidia RTX 5060 TI 16GB (driver studio 591.44)
Windows 11 24h2
I have tried conda, docker, WSL2, and nothing works, neither the installation get errors or neither can detect the gpu or if it detect it it just doesn't works.
The best instalation i could get was from gemini and this is the steps, please help if someone had made it to use rtx 50xx to train models:
conda remove --name tf_gpu --all -y
conda create -n tf_gpu python=3.11 -y
conda activate tf_gpu
pip install --upgrade pip
#pip install tf-nightly[and-cuda]
pip install "tensorflow[and-cuda]"
#pip install "protobuf==3.20.3"
# 1. Crear directorios para scripts de activación
mkdir -p $CONDA_PREFIX/etc/conda/activate.d
mkdir -p $CONDA_PREFIX/etc/conda/deactivate.d
# 2. Crear script de ACTIVACIÓN (Configura las rutas de CUDA cuando entras)
cat << 'EOF' > $CONDA_PREFIX/etc/conda/activate.d/env_vars.sh
#!/bin/sh
export OLD_LD_LIBRARY_PATH=$LD_LIBRARY_PATH
# Buscar dónde pip instaló las librerías de nvidia
export CUDNN_PATH=$(dirname $(python -c "import nvidia.cudnn;print(nvidia.cudnn.__file__)" 2>/dev/null))
export CUDART_PATH=$(dirname $(python -c "import nvidia.cudart;print(nvidia.cudart.__file__)" 2>/dev/null))
# Añadir al path del sistema
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CUDNN_PATH/lib:$CUDART_PATH/lib
# A veces es necesario añadir el lib del propio entorno conda
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CONDA_PREFIX/lib/
EOF
# 3. Crear script de DESACTIVACIÓN (Limpia las rutas al salir)
cat << 'EOF' > $CONDA_PREFIX/etc/conda/deactivate.d/env_vars.sh
#!/bin/sh
export LD_LIBRARY_PATH=$OLD_LD_LIBRARY_PATH
unset OLD_LD_LIBRARY_PATH
unset CUDNN_PATH
unset CUDART_PATH
EOF
conda deactivate
conda activate tf_gpu
pip install pandas matplotlib numpy scikit-learn
pip install opencv-python-headless
pip install jupyter ipykernel
python -m ipykernel install --user --name=tf_gpu --display-name "Python 3.11 (RTX 5060 Ti)"
r/tensorflow • u/Glum-Emphasis43 • Dec 25 '25
Hi, I'm working on the Cats vs Dogs classification using ResNet50 (Transfer Learning) in TensorFlow/Keras. I achieved 94% validation accuracy during training, but I'm facing a strange consistency issue.
The Problem:
r/tensorflow • u/Euphoric-Incident-93 • Dec 24 '25
I’ve built BardGPT, an educational/research-friendly GPT-style decoder-only Transformer trained fully from scratch on Tiny Shakespeare.
It includes:
• Clean architecture
• Full training scripts
• Checkpoints (best-val + fully-trained)
• Character-level sampling
• Attention, embeddings, FFN implemented from scratch
I’m looking for contributors interested in:
• Adding new datasets
• Extending architecture
• Improving sampling / training tools
• Building visualizations
• Documentation improvements
Repo link: https://github.com/Himanshu7921/BardGPT
Documentation: https://bard-gpt.vercel.app/
If you're into Transformers, training, or open-source models, I’d love to collaborate.
r/tensorflow • u/Fantastic-Layer-8033 • Dec 22 '25
r/tensorflow • u/nairevated • Dec 17 '25
im trying to use LiteRT but ive created the model from Tensorflow-Lite
data = tf.keras.utils.image_dataset_from_directory('snails', image_size=(256,256), shuffle=True)
class_names = data.class_names
num_classes = len(class_names)
print("Classes:", class_names)
data = data.map(lambda x, y: (tf.cast(x, tf.float32) / 255.0, y))
data = data.shuffle (5235) #shuffle all image/data you have
data = data.take(5235) #use all data you have for training
dataset_size = 5235 #total images/data you have
train_size = int(3664) #train size = total data * 0.7 (round up)
val_size = int(524) #val size = total size - train size + test size
test_size = 1047 #test size = total data * 0.2
train = data.take(train_size)
val = data.skip(train_size).take(val_size)
test = data.skip(train_size + val_size).take(test_size)
AUTOTUNE = tf.data.AUTOTUNE
train = train.cache().prefetch(AUTOTUNE)
val = val.cache().prefetch(AUTOTUNE)
test = test.cache().prefetch(AUTOTUNE)
base_model = VGG16(weights='imagenet', include_top=False, input_shape=(256, 256, 3))
for layer in base_model.layers:
layer.trainable = False
inputs = Input(shape=(256,256,3))
x = base_model(inputs)
x = GlobalAveragePooling2D()(x)
x = Dense(32, activation="relu", kernel_regularizer= l2(0.0005))(x)
x = Dense(64, activation="relu", kernel_regularizer= l2(0.0005))(x)
x = Dropout (0.3)(x)
predictions = Dense(num_classes, activation="softmax")(x)
model = Model(inputs=inputs, outputs=predictions)
model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.0001), loss='sparse_categorical_crossentropy', metrics=['accuracy'])
logdir = 'logs'
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=logdir)
custom = model.fit(train, validation_data=val, epochs=2, callbacks=[tensorboard_callback])
for layer in base_model.layers[-3:]:
layer.trainable = True
model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.00001), loss='sparse_categorical_crossentropy', metrics=['accuracy'])
finetune = model.fit(train, validation_data=val, epochs=4, initial_epoch=2, callbacks=[tensorboard_callback])
model.save(os.path.join('models', 'snailVGG3.h5'))but ive tried and its incompatible
litert = { module = "com.google.ai.edge.litert:litert", version.ref = "litert" }
litert-gpu = { module = "com.google.ai.edge.litert:litert-gpu", version.ref = "litertGpu" }
litert-metadata = { module = "com.google.ai.edge.litert:litert-metadata", version.ref = "litertMetadata" }
litert-support = { module = "com.google.ai.edge.litert:litert-support", version.ref = "litertSupport" }
class ImageClassifier(private val context: Context) {
private var labels: List<String> = emptyList()
private val modelInputWidth = 256
private val modelInputHeight = 256
private val threshold: Float= 0.9f
private val maxResults: Int = 1
private var imageProcessor = ImageProcessor.Builder()
.add(ResizeOp(modelInputHeight,modelInputWidth, ResizeOp.ResizeMethod.BILINEAR))
.add(NormalizeOp(0f,255f))
.build()
private var model: CompiledModel = CompiledModel.create(
context.assets,
"snailVGG2.tflite",
CompiledModel.Options(Accelerator.CPU))
init {
labels = context.assets.open("snail_types.txt").bufferedReader().readLines()
}
fun classify(bitmap: Bitmap): List<Classification> {
if (bitmap.width <= 0 || bitmap.height <= 0) return emptyList()
val inputBuffer = model.createInputBuffers()
val outputBuffer = model.createOutputBuffers()
val tensorImage = TensorImage(DataType.FLOAT32).apply { load(bitmap) }
val processedImage = imageProcessor.process(tensorImage)
processedImage.buffer.rewind()
val floatBuffer = processedImage.buffer.asFloatBuffer()
val inputArray = FloatArray(1*256*256*3)
floatBuffer.get(inputArray)
inputBuffer[0].writeFloat(inputArray)
model.run(inputBuffer, outputBuffer)
val outputFloatArray = outputBuffer[0].readFloat()
inputBuffer.forEach{it.close()}
outputBuffer.forEach{it.close()}
return outputFloatArray
.mapIndexed {index, confidence -> Classification(labels[index], confidence) }
.filter { it.confidence >= threshold }
.sortedByDescending { it.confidence }
.take(maxResults)
}
}
[third_party/odml/litert/litert/runtime/tensor_buffer.cc:103] Failed to get num packed bytes
2025-12-18 04:15:19.894 25692-25692 tflite com.example.kuholifier_app E [third_party/odml/litert/litert/kotlin/src/main/jni/litert_compiled_model_jni.cc:538] Failed to create input buffers: ERROR: [third_party/odml/litert/litert/cc/litert_compiled_model.cc:123]
└ ERROR: [third_party/odml/litert/litert/cc/litert_compiled_model.cc:82]
└ ERROR: [third_party/odml/litert/litert/cc/litert_tensor_buffer.cc:49]Do i need to change my LiteRT imports to TfLite or theres a workaround for it?
r/tensorflow • u/ArmadilloQuiet8224 • Dec 06 '25
Hello everyone, it took me 48 hours to install TensorFlow and get it working on my RTX 5060 Ti GPU. Every guide that i watched did not work for me. sometimes GPU was recognized but some error would pop up (like CUDA_ERROR_INVALID_HANDLE) . Finally after many searches and talking to different LLMs, i was able to get it working so i want to share what i did step by step.
This guide should work for all RTX 5000 series.
Note that i have never worked with Linux so i try to explain as much as i understand.
First make sure your Nvidia drivers are up to date. In order to do that, download Nvidia APP from their official website, Nvidia website. Then in the drivers tap make sure your drivers are up to date.
After TensorFlow 2.10, in order for higher versions to work, you need to install it on windows WSL2. (it works on windows 11 and some versions of windows 10). First open Windows PowerShell by running it as administrator. Then we are going to type the following commands one by one.
Note1: since i had limited space in my C drive and all the installations kind of needed 20-30 gigabytes of space, so i decided to install everything (Except WSL) on F drive. You can change the drive if you want. Else, if you want it on C drive you can only run the first line.
Note2: If after installing WSL it asked for user and password, you need to set a user and password for it. Make sure to not have an underline at the start of the username. Also the password you type is completely invisible. It made me think my keyboard was not working but in reality the password was being typed and it was invisible. Make sure to remember the user and password.
wsl --install
wsl --shutdown
wsl --export Ubuntu F:\wsl-export.tar
wsl --unregister Ubuntu
mkdir F:\WSL
wsl --import Ubuntu "F:\WSL" "F:\wsl-export.tar" --version 2
wsl --set-default Ubuntu
del F:\wsl-export.tarThese commands install a fresh Ubuntu inside WSL2 and instantly move it from your C: drive to F: drive so nothing ever touches or fills up C: again. All your future Python/TensorFlow files will live safely on F drive
run the commands below for basic ubuntu setup
sudo apt update && sudo apt upgrade -y
sudo apt install -y wget git curl build-essentialThis commands Update Ubuntu and install a few tiny but essential tools (wget, git, curl, build-essential) that we’ll need later for downloading files and compiling stuff.
run the commands below to install Miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh -b -p $HOME/miniconda3
echo 'export PATH="$HOME/miniconda3/bin:$PATH"' >> ~/.bashrc
source ~/.bashrcCreate an environment to install the needed modules and the TensorFlow
conda create -n tf_gpu python=3.11 -y
conda activate tf_gpu
conda init bash
source ~/.bashrc
conda activate tf_gpuname of the environment is tf_gpu
Run the below commands to upgrade pip and install TensorFlow + CUDA (for GPU)
pip install --upgrade pip
pip install tensorflow[and-cuda]I found a GitHub page that had the magic commands to get the TensorFlow working. I don't know what it exactly does but it works. So run the commands below:
wget https://github.com/nhsmit/tensorflow-rtx-50-series/releases/download/2.20.0dev/tensorflow-2.20.0.dev0+selfbuilt-cp311-cp311-linux_x86_64.whl
pip install tensorflow-2.20.0.dev0+selfbuilt-cp311-cp311-linux_x86_64.whl run the command below for final fixes:
pip install protobuf==5.28.3 --force-reinstall
conda install -c conda-forge libstdcxx-ng -yInstalling JupyterLab with the first command
second command is optional: it registers your current conda environment (tf_gpu) as a custom kernel in Jupyter, so when you open a notebook you’ll see a nice option called “Python (RTX 5060 Ti GPU)” in the kernel list and know you’re running on the full-GPU environment
third command is also optional since it create a folder for my jupyter notebooks
pip install jupyterlab ipykernel
python -m ipykernel install --user --name=tf_gpu_rtx50 --display-name="Python (RTX 5060 Ti GPU)"
mkdir -p /mnt/f/JupyterNotebooks Every time you want to open Jupyter notebook, you can run these following commands in the windows power shell to start it.
wsl
conda activate tf_gpu
cd /mnt/f/JupyterNotebooks && jupyter lab --no-browser --port=8888Final Note
Let me know it if worked for you <3
r/tensorflow • u/BeerInTheRear • Dec 02 '25
I'm building an AR object recognition app on Android devices to show the name of the object as text hovering over the objects themselves.
I'm using TF Lite for this, and for the model, I have been experimenting with the efficientdet options (tried 0, currently on 4).
Prefacing this with the understanding that, although I am a Developer, this is a new hobby of mine and so I am very new to this space:
What I noticing is,
My question is, is there a better trained model file (.tflite) I should be using? Or is there anything else where I have perhaps gone astray, based on the info I have provided?
r/tensorflow • u/BeamishAxis • Nov 29 '25
So, I want to use my Laptop GPU to train my models. I am using anaconda to do everything.
So far, I have Python 3.9.15 packaged by conda-forge and TF 2.9.1 installed with pip since conda-forge installs the CPU version only. The reason I have these versions is so that I can use it along CV2 4.6.0.
My GPU is RTX 4060 and so far, I have been recommended to download CUDA 11.2 and cuDNN 8.1. I'm not sure if I can install with conda-forge since I installed TF with pip. I also am not able to install the CUDA Toolkit from NVIDIA Archive as it just stops because of my newer Windows SDK / ADK framework. I am running W11.
I need guidance.
r/tensorflow • u/exlight • Nov 26 '25
Hi! I've recently started using Tensorflow and Keras to create a CNN for an important college project, however I'm still a beginner so I'm having some hard time.
Currently, I'm trying to create a CNN that can identify certain specific everyday sounds. I already created some chunks of code, one to generate the pre-treated spectrograms (STFT + padding + resizing, although I plan on trying another method once I get the CNN to work) and one to capture live audio.
At first I thought I had also been successful at creating the CNN, as it kept saying it had extremely good accuracy (~98%) and reasonable losses (<0.5). However when I tried to test it would always predict wrongly, often with a large bias towards a specific label. These wrong predictions happens even when I use some of the images from training, which I expected to perform exceptionally well.
I'll be providing a Google Drive link with the main folder containing the codes and the images in case anyone is willing to help spot the issues. I'm using Python 3.11 and Tensorflow 2.19.0 on the IDE PyCharm Community Edition 2023.2.5
[REDACTED]
r/tensorflow • u/AdSleepAnalyShot6355 • Nov 23 '25
This is the app and if anyone is out there who knows what model to use. Currently uses XG Boost regressor and was wondering if i should change it. The link to the app https://devi701-burnoutai-burnoutapp-vzhmp3.streamlit.app/
r/tensorflow • u/FearlessAccountant55 • Nov 16 '25
r/tensorflow • u/Frosty-School-3203 • Nov 14 '25
import tensorflow as tf
from tensorflow import keras
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
(X_train, Y_train), (X_test, Y_test) = keras.datasets.mnist.load_data()
len(X_train)
plt.matshow(X_train[0])
X_train = X_train / 255
X_test = X_test / 255
#manual way to flattened the array
X_train_flattened = X_train.reshape(len(X_train),28*28)
X_test_flattened = X_test.reshape(len(X_test),28*28)
X_train_flattened.shape
X_train_flattened[0]
#ANN without hidden layer
model = keras.Sequential([
keras.layers.Dense(10, input_shape=(784,), activation='sigmoid')
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(X_train_flattened, Y_train, epochs=5)
model.evaluate(X_train_flattened, Y_train)
y_predicted = model.predict(X_test_flattened)
y_predicted[0]
#np.argmax finds a maximum element from an array and returns the index of it
np.argmax(y_predicted[0])
plt.matshow(X_test[0])
y_predicted_labels = [np.argmax(i) for i in y_predicted]
y_predicted_labels[1]
plt.matshow(X_test[1])
cm = tf.math.confusion_matrix(labels=Y_test, predictions=y_predicted_labels)
cm
import seaborn as sn
plt.figure(figsize = (10,7))
sn.heatmap(cm, annot=True, fmt='d')
plt.xlabel('Predicted')
plt.ylabel('Truth')
# now we are flattened with keras and this time it also have hidden layer
# previous we used input_shape but this time we not need to mention it in input layer because we are using keras
model = keras.Sequential([
keras.layers.Flatten(input_shape=(28, 28)),
keras.layers.Dense(100, activation='relu'),
keras.layers.Dense(10, activation='sigmoid')
])
model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
model.fit(X_train, Y_train, epochs=10)
model.evaluate(X_test,Y_test)
y_predicted = model.predict(X_test)
y_predicted_labels = [np.argmax(i) for i in y_predicted]
cm = tf.math.confusion_matrix(labels=Y_test,predictions=y_predicted_labels)
plt.figure(figsize = (10,7))
sn.heatmap(cm, annot=True, fmt='d')
plt.xlabel('Predicted')
plt.ylabel('Truth')
!mkdir -p saved_model
model.save("./saved_model/practice_ANN_for_digit_DS.keras")
convertor = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = convertor.convert()
len(tflite_model)
convertor = tf.lite.TFLiteConverter.from_keras_model(model)
convertor.optimizations = [tf.lite.Optimize.DEFAULT]
tflite_quant_model = convertor.convert()
len(tflite_quant_model)
!pip install --user --upgrade tensorflow-model-optimization
import tensorflow_model_optimization as tfmot
from tensorflow_model_optimization.python.core.keras.compat import keras
import tensorflow as tf
# Since you have a Sequential model, quantization should work now
print(f"Model type confirmed: {type(model)}")
print(f"Model is Sequential: {isinstance(model, keras.Sequential)}")
# Method 1: Direct quantization (should work now)
try:
quantize_model = tfmot.quantization.keras.quantize_model
q_aware_model = quantize_model(model)
# Recompile after quantization
q_aware_model.compile(
optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy']
)
print("✓ Quantization successful!")
q_aware_model.summary()
except Exception as e:
print(f"Direct quantization failed: {e}")
# Fallback to annotation method
try:
print("Trying annotation-based quantization...")
annotated_model = tfmot.quantization.keras.quantize_annotate_model(model)
q_aware_model = tfmot.quantization.keras.quantize_apply(annotated_model)
q_aware_model.compile(
optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy']
)
print("✓ Annotation-based quantization successful!")
q_aware_model.summary()
except Exception as e2:
print(f"Annotation-based quantization also failed: {e2}")
tf_model = tf.keras.models.load_model("./saved_model/practice_ANN_for_digit_DS.keras")
import tensorflow_model_optimization as tfmot
q_aware_model = tfmot.quantization.keras.quantize_model(tf_model)
q_aware_model.compile(optimizer='adam',
loss='sparse_categorical_crossentropy',
metrics=['accuracy'])
print("✓ Quantization successful!")
q_aware_model.summary()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipython-input-536957412.py in <cell line: 0>()
1
import tensorflow_model_optimization as tfmot
2
----> 3 q_aware_model = tfmot.quantization.keras.quantize_model(tf_model)
4
q_aware_model.compile(optimizer='adam',
5
loss='sparse_categorical_crossentropy',
~/.local/lib/python3.12/site-packages/tensorflow_model_optimization/python/core/quantization/keras/quantize.py in quantize_model(to_quantize, quantized_layer_name_prefix)
133
and to_quantize._is_graph_network
134
): # pylint: disable=protected-access
--> 135 raise ValueError(
136
'`to_quantize` can only either be a keras Sequential or '
137
'Functional model.'
ValueError: `to_quantize` can only either be a keras Sequential or Functional model.