- 1、本文档共10页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
John Olafenwa Follow
A 22 years old, self Taught Computer Programmer and Deep Neural Network Practitioner with
focus on Computer Vision. Lives In Nigeria.
Jan 19 · 5 min read
Basics of image classi cation with Keras
In my previous post, I delved into some of the theoretical concepts
underlying arti cial neural networks. In this post, I would be
explaining some common operations that you would frequently need in
keras. First, how to save models and use them for prediction later,
displaying images from the dataset and loading images from our
system and predicting their class.
Fire up your IDE if you haven’t done so and read on.
SAVING MODELS
Training models is a very slow process, nobody want’s to do that every
time, fortunately, we only need to train our model once, save it and
then we can load it anytime and use it to predict new images.
Keras saves models in the .h5 format, so in case you skipped installing
h5py in the rst tutorial I posted, pleas run
pip3 install h5py
We would also need matplotlib to visualize our image, hence, run
pip3 install matplotlib
Here is the code for the rst tutorial
import keras
from keras.datasets import mnist
from keras.layers import Dense
from keras.models import Sequential
from keras.optimizers import SGD
(train_x, train_y) , (test_x, test_y) mnist.load_data()
#train_x train_x.astype(float32) / 255
#test_x test_x.astype(float32) / 255
print(train_x.shape)
print(train_y.shape)
print(test_x.shape)
print(test_y.shape)
train_x train_x.reshape(60000,784)
test_x test_x.reshape(10000,784)
train_y keras.utils.to_categorical(train_y,10)
test_y keras.utils.to_categorical(test_y,10)
model Sequential()
model.add(Dense(units 128,activation relu,input_shape
(784,)
您可能关注的文档
- 1A - Fudan 2014 Salary Classification Question英文文献资料.pdf
- 2_PRoNTo_Course_Classification英文文献资料.pdf
- 3 Bias and variance trade-off英文文献资料.pdf
- 3_06_performing_classification英文文献资料.pdf
- 4-Situational Awareness in Intelligent Vehicles英文文献资料.pdf
- 5-nonlinear-classification-and-regression-with-decision-trees英文文献资料.pdf
- 7Beef_Cattle_Production_and_Trade_7_Chinese_and_South_East_Asian_cattle_production英文文献资料.pdf
- 08_Text_Classification-_Evaluation_7-17英文文献资料.pdf
- 8 - Supervised Learning - Discriminative Classification英文文献资料.pdf
- 8)20161007 Classification Probabilistic Generative Model英文文献资料.pdf
文档评论(0)