python, tensorflow, testingTensorFlow: training on my own imageCalling an external command in PythonWhat are metaclasses in Python?Is there a way to run Python on Android?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory in Python?How to get the current time in PythonHow can I make a time delay in Python?Understanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

What detail can Hubble see on Mars?

How is trade in services conducted under the WTO in the absence of the Doha conclusion?

Where did Lovecraft write about Carcosa?

Is there a reason why Turkey took the Balkan territories of the Ottoman Empire, instead of Greece or another of the Balkan states?

What word describes the sound of an instrument based on the shape of the waveform of its sound?

What happens if I accidentally leave an app running and click "Install Now" in Software Updater?

Given a safe domain, are subdirectories safe as well?

Installing Debian 10, upgrade to stable later?

Picking a theme as a discovery writer

Make me a minimum magic sum

Game artist computer workstation set-up – is this overkill?

Referring to person by surname, keep or omit "von"?

How can I finally understand the confusing modal verb "мочь"?

Dual frame in Riemannian metrics.

Can an Iranian citizen enter the USA on a Dutch passport?

Changing stroke width vertically but not horizontally in Inkscape

Hostile Divisor Numbers

Python 3 - simple temperature program version 1.3

Stereochemical outcomes in opening of vinyl epoxides

Why are condenser mics so much more expensive than dynamics?

Convert Numbers To Emoji Math

As a GM, is it bad form to ask for a moment to think when improvising?

Emergency stop in plain TeX, pdfTeX, XeTeX and LuaTeX?

What does the coin flipping before dying mean?



python, tensorflow, testing


TensorFlow: training on my own imageCalling an external command in PythonWhat are metaclasses in Python?Is there a way to run Python on Android?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory in Python?How to get the current time in PythonHow can I make a time delay in Python?Understanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















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()



The code below is the handwritten digits for my model using a cnn.




import tensorflow as tf
from tensorflow import keras
import numpy as np


mnist = tf.keras.datasets.mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()

training_images=training_images.reshape(60000, 28, 28, 1)
training_images=training_images / 255.0
test_images = test_images.reshape(10000, 28, 28, 1)
test_images=test_images/255.0

class myCallback(tf.keras.callbacks.Callback):
def on_epoch_end(self, epoch, logs=):
if(logs.get('acc')>=0.998):
print("nReached 99.8% accuracy so cancelling training!")
self.model.stop_training = True

callbacks = myCallback()

model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(64, (3,3), activation='relu', input_shape=(28, 28, 1)),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(training_images, training_labels, epochs=20, callbacks=[callbacks])



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 achieves the state of the art (99.8%) correct classification on the model however, I am still questioning how to do run this against files that I upload, or from the disk. The code that I have provided from coursera gives an example of how to do this for using an upload image button, however, this is running files from google drive, and I would like to do so on from my own disk as I am not using colab/google to run this project.
Thank you for your time, as I hope the answer helps others as well.
Cody Quist










share|improve this question
























  • I have found my answer. If this helps at least one person, comment here and Ill share the code that I found.

    – Cody Quist
    Mar 23 at 9:26

















0















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()



The code below is the handwritten digits for my model using a cnn.




import tensorflow as tf
from tensorflow import keras
import numpy as np


mnist = tf.keras.datasets.mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()

training_images=training_images.reshape(60000, 28, 28, 1)
training_images=training_images / 255.0
test_images = test_images.reshape(10000, 28, 28, 1)
test_images=test_images/255.0

class myCallback(tf.keras.callbacks.Callback):
def on_epoch_end(self, epoch, logs=):
if(logs.get('acc')>=0.998):
print("nReached 99.8% accuracy so cancelling training!")
self.model.stop_training = True

callbacks = myCallback()

model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(64, (3,3), activation='relu', input_shape=(28, 28, 1)),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(training_images, training_labels, epochs=20, callbacks=[callbacks])



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 achieves the state of the art (99.8%) correct classification on the model however, I am still questioning how to do run this against files that I upload, or from the disk. The code that I have provided from coursera gives an example of how to do this for using an upload image button, however, this is running files from google drive, and I would like to do so on from my own disk as I am not using colab/google to run this project.
Thank you for your time, as I hope the answer helps others as well.
Cody Quist










share|improve this question
























  • I have found my answer. If this helps at least one person, comment here and Ill share the code that I found.

    – Cody Quist
    Mar 23 at 9:26













0












0








0








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()



The code below is the handwritten digits for my model using a cnn.




import tensorflow as tf
from tensorflow import keras
import numpy as np


mnist = tf.keras.datasets.mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()

training_images=training_images.reshape(60000, 28, 28, 1)
training_images=training_images / 255.0
test_images = test_images.reshape(10000, 28, 28, 1)
test_images=test_images/255.0

class myCallback(tf.keras.callbacks.Callback):
def on_epoch_end(self, epoch, logs=):
if(logs.get('acc')>=0.998):
print("nReached 99.8% accuracy so cancelling training!")
self.model.stop_training = True

callbacks = myCallback()

model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(64, (3,3), activation='relu', input_shape=(28, 28, 1)),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(training_images, training_labels, epochs=20, callbacks=[callbacks])



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 achieves the state of the art (99.8%) correct classification on the model however, I am still questioning how to do run this against files that I upload, or from the disk. The code that I have provided from coursera gives an example of how to do this for using an upload image button, however, this is running files from google drive, and I would like to do so on from my own disk as I am not using colab/google to run this project.
Thank you for your time, as I hope the answer helps others as well.
Cody Quist










share|improve this question
















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()



The code below is the handwritten digits for my model using a cnn.




import tensorflow as tf
from tensorflow import keras
import numpy as np


mnist = tf.keras.datasets.mnist
(training_images, training_labels), (test_images, test_labels) = mnist.load_data()

training_images=training_images.reshape(60000, 28, 28, 1)
training_images=training_images / 255.0
test_images = test_images.reshape(10000, 28, 28, 1)
test_images=test_images/255.0

class myCallback(tf.keras.callbacks.Callback):
def on_epoch_end(self, epoch, logs=):
if(logs.get('acc')>=0.998):
print("nReached 99.8% accuracy so cancelling training!")
self.model.stop_training = True

callbacks = myCallback()

model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(64, (3,3), activation='relu', input_shape=(28, 28, 1)),
tf.keras.layers.MaxPooling2D(2, 2),
tf.keras.layers.Flatten(),
tf.keras.layers.Dense(128, activation='relu'),
tf.keras.layers.Dense(10, activation='softmax')
])

model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(training_images, training_labels, epochs=20, callbacks=[callbacks])



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 achieves the state of the art (99.8%) correct classification on the model however, I am still questioning how to do run this against files that I upload, or from the disk. The code that I have provided from coursera gives an example of how to do this for using an upload image button, however, this is running files from google drive, and I would like to do so on from my own disk as I am not using colab/google to run this project.
Thank you for your time, as I hope the answer helps others as well.
Cody Quist







python tensorflow testing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 4:59







Cody Quist

















asked Mar 23 at 4:47









Cody QuistCody Quist

612




612












  • I have found my answer. If this helps at least one person, comment here and Ill share the code that I found.

    – Cody Quist
    Mar 23 at 9:26

















  • I have found my answer. If this helps at least one person, comment here and Ill share the code that I found.

    – Cody Quist
    Mar 23 at 9:26
















I have found my answer. If this helps at least one person, comment here and Ill share the code that I found.

– Cody Quist
Mar 23 at 9:26





I have found my answer. If this helps at least one person, comment here and Ill share the code that I found.

– Cody Quist
Mar 23 at 9:26












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55310692%2fpython-tensorflow-testing%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55310692%2fpython-tensorflow-testing%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현