'TensorFlow: how to create training and testing image datasets

I've been looking forever on the internet trying to create, train and test my own tensorflow model. But I have unsuccessfully done that. From investigating my code, I think it's how I create my dataset of images. Most online tutorials would just import a prepared dataset, but my dataset is specifically for use-case diagrams and holds each element within those diagrams. My aim is to train a tensorflow model to predict each element in a diagram and hopefully the errors too. Here's the code:

def createDataSet(labelList, label, filePath, width, height):
    dataList = []
    for img in os.listdir(filePath):
        filename = str(img)
        if filename[len(filename) - 3:len(filename)] != "npy":
            pic = cv.imread(os.path.join(filePath, img))
            pic = cv.cvtColor(pic, cv.COLOR_BGR2RGB)
            pic = cv.resize(pic, (width, height))
            dataList.append(pic)
            labelList.append(label)
return dataList, labelList
# appending the pics to the training data list
training_dataset, train_labels = createDataSet(train_labels, train_label, path, width, height)
test_dataset, test_labels = createDataSet(test_labels, test_label, path2, width, height)
#converting the list to numpy array and saving it to a file using #numpy.save
np.save(os.path.join(path,train_label),np.array(training_dataset))
np.save(os.path.join(path2,test_label),np.array(test_dataset))
#loading the saved file once again
train_images = np.array(training_dataset)
test_images = np.array(test_dataset)

As of now, the function creates a list which will be saved as a numpy array and that numpy array will be used for my model. But it causes errors like UNIMPLEMENTED: Cast string to float is not supported. I'm sure that I'm creating the train, test data and the labels for both incorrectly



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source