0
$\begingroup$

I need to use keras.preprocessing.image_dataset_from_directory() for a large dataset. My GPU is RTX so I would also like to use mixed precision training in Tensorflow 2.5.

How do I cast the output images of the generator to float16? I've tried the .cast() method with no success. I'd also like to avoid generic scaling as I want to rigidly control normalisation factors and if possible scale my images from -1 to 1 with a uniform (2*x/255)-1 where x is the image. I also tried to pass a straight np.float16() in that scaling function applied to the TF dataset. No success either. What am I missing?

$\endgroup$
0
$\begingroup$

Found it! It's a matter of using the cast() method in the rescaling function. eg:

def rescale(img, label):
  sc_img=(tf.cast(img, tf.float16) / 127.5)-1
  return sc_img, label
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.