Getting a TypeError when using cuda, but not when using cpu

Im trying to import a lot of images into tensorflow, to traing a Keras AI, to do some image enhancement for me.

When disabling my gpu with:

import os
os.environ[“CUDA_VISIBLE_DEVICES”] = “-1”

The code runs absolutely fine, but the training takes ages. But when i enable my RTX 3060, with Cuda v11.7 installed proberly, i get the error:’

TypeError: Input ‘filename’ of ‘ReadFile’ Op has type float32 that does not match expected type of string.

Why? how can it change the datatype, that i switch from CPU to GPU?


The failing code is this:

def read_image(image_path):
image = This Line
image = tf.image.decode_png(image, channels=3)
image.set_shape([None, None, 3])
image = tf.cast(image, dtype=tf.float32) / 255.0
return image

def random_crop(low_image, enhanced_image):
low_image_shape = tf.shape(low_image)[:2]
low_w = tf.random.uniform(
shape=(), maxval=low_image_shape[1] – IMAGE_SIZE + 1, dtype=tf.int32
low_h = tf.random.uniform(
shape=(), maxval=low_image_shape[0] – IMAGE_SIZE + 1, dtype=tf.int32
enhanced_w = low_w
enhanced_h = low_h
low_image_cropped = low_image[
low_h : low_h + IMAGE_SIZE, low_w : low_w + IMAGE_SIZE
enhanced_image_cropped = enhanced_image[
enhanced_h : enhanced_h + IMAGE_SIZE, enhanced_w : enhanced_w + IMAGE_SIZE
return low_image_cropped, enhanced_image_cropped

def load_data(low_light_image_path, enhanced_image_path):
low_light_image = read_image(low_light_image_path) And this line
enhanced_image = read_image(enhanced_image_path)
low_light_image, enhanced_image = random_crop(low_light_image, enhanced_image)
return low_light_image, enhanced_image

def get_dataset(low_light_images, enhanced_images):
dataset =, enhanced_images))
dataset =,
dataset = dataset.batch(BATCH_SIZE, drop_remainder=True)
return dataset

train_low_light_images = sorted(glob(“./lol_dataset/our485/low/*”))[:MAX_TRAIN_IMAGES]
train_enhanced_images = sorted(glob(“./lol_dataset/our485/high/*”))[:MAX_TRAIN_IMAGES]

And no, this is not my code, but grapped from a github repository. It’s a prove of concept, to see if i can do, what i want it to do. I’ll rewrite it, if i decide to go forward with Keras

submitted by /u/lynet_101
[visit reddit] [comments]

Leave a Reply

Your email address will not be published.