I am new to machine learning and have tried many different ways to create an image data pipeline. I went through Udacity and Google Tutorials and they all work great, so long as you get your image data from TF Hub or some other online source. Unfortunately, I haven't found ANY end-to-end examples (that work) of how to do this correctly when you have your own locally stored images. This is as close as I have gotten.
I have my own image data and am trying to get it in the correct Tensor format to fit my model (I'm using a feature extractor from TensorFlow Hub). I froze all the layers, added a binary output layer.
I get the following error when I run a training session with train_batches model.fit
UnimplementedError: Cast string to float is not supported
I'm pretty sure it has to do with the class labels being strings (pulled from folder name). Is there anyway I can pass a dictionary with values 0 and 1 to relabel?
Am I missing something much more crucial than this?
image_path_list = glob('/content/sample_data/tng (1)/*/*.jpg')
data = tf.data.Dataset.list_files(image_path_list)
print(image_path_list)
print()
print(data)
def load_images(path):
image = tf.io.read_file(path)
image = tf.io.decode_jpeg(image, channels=3)
label = tf.strings.split(path, os.path.sep)[-2]
return image, label
data = data.map(load_images)
def preprocess(image, label):
image = tf.image.resize(image, (IMG_RES, IMG_RES))
image /= 255.
return image, label
BATCH_SIZE = 1
train_batches = data.shuffle(len(image_path_list)).map(preprocess).batch(BATCH_SIZE).prefetch(1)