The code below is from coursera
import numpy as np
from google.colab import files
from keras.preprocessing import image
uploaded = files.upload()
for fn in uploaded.keys():
# predicting images
path = '/content/' + fn
img = image.load_img(path, target_size=(300, 300))
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
images = np.vstack([x])
classes = model.predict(images, batch_size=10)
print(classes[0])
if classes[0]>0.5:
print(fn + " is a human")
else:
print(fn + " is a horse")
The code below is from stackoverflow
# step 1
filenames = tf.constant(['im_01.jpg', 'im_02.jpg', 'im_03.jpg', 'im_04.jpg'])
labels = tf.constant([0, 1, 0, 1])
# step 2: create a dataset returning slices of `filenames`
dataset = tf.data.Dataset.from_tensor_slices((filenames, labels))
# step 3: parse every image in the dataset using `map`
def _parse_function(filename, label):
image_string = tf.read_file(filename)
image_decoded = tf.image.decode_jpeg(image_string, channels=3)
image = tf.cast(image_decoded, tf.float32)
return image, label
dataset = dataset.map(_parse_function)
dataset = dataset.batch(2)
# step 4: create iterator and final input tensor
iterator = dataset.make_one_shot_iterator()
images, labels = iterator.get_next()
SO, I have seen this post regarding training on my own data (images), however, this is not for the current version of tensorflow==2.0.0.0alpha0 in which I am trying to write code in.
The purpose of the program is to classify a single image that I upload (such as a drawing/writing of my own handwritten digits and see if my model & my handwriting is legible to the computer. I will not being using multiple number values, nor letters as in alpha-numeric, just simply digits (singular integers) for now. I have already created a cnn that acheives the state of the art (99.8%) correct classification on the model that I have not listed in this post, however, I am still questioning how to do run this against files that I upload, or from the disk. Thank you for your time, as I hope the answer helps others as well. Cody Quist
Aucun commentaire:
Enregistrer un commentaire