使用TensorFlow进行图像识别 (Image Recognition using TensorFlow)

TensorFlow includes a special feature of image recognition and these images are stored in a specific folder. With relatively same images, it will be easy to implement this logic for security purposes.

TensorFlow包含图像识别的特殊功能,并且这些图像存储在特定的文件夹中。 对于相对相同的映像,出于安全目的很容易实现此逻辑。

The folder structure of image recognition code implementation is as shown below −

图像识别代码实现的文件夹结构如下图所示-

The dataset_image includes the related images, which need to be loaded. We will focus on image recognition with our logo defined in it. The images are loaded with “load_data.py” script, which helps in keeping a note on various image recognition modules within them.

dataset_image包括需要加载的相关图像。 我们将专注于其中定义了徽标的图像识别。 图像使用“ load_data.py”脚本加载,这有助于在其中的各个图像识别模块上保留注释。


import pickle
from sklearn.model_selection import train_test_split
from scipy import miscimport numpy as np
import oslabel = os.listdir("dataset_image")
label = label[1:]
dataset = []for image_label in label:images = os.listdir("dataset_image/"+image_label)for image in images:img = misc.imread("dataset_image/"+image_label+"/"+image)img = misc.imresize(img, (64, 64))dataset.append((img,image_label))
X = []
Y = []for input,image_label in dataset:X.append(input)Y.append(label.index(image_label))X = np.array(X)
Y = np.array(Y)X_train,y_train, = X,Ydata_set = (X_train,y_train)save_label = open("int_to_word_out.pickle","wb")
pickle.dump(label, save_label)
save_label.close()

The training of images helps in storing the recognizable patterns within specified folder.

图像训练有助于将可识别的图案存储在指定的文件夹中。


import numpy
import matplotlib.pyplot as pltfrom keras.layers import Dropout
from keras.layers import Flatten
from keras.constraints import maxnorm
from keras.optimizers import SGD
from keras.layers import Conv2D
from keras.layers.convolutional import MaxPooling2D
from keras.utils import np_utils
from keras import backend as Kimport load_data
from keras.models import Sequential
from keras.layers import Denseimport keras
K.set_image_dim_ordering('tf')# fix random seed for reproducibility
seed = 7
numpy.random.seed(seed)# load data
(X_train,y_train) = load_data.data_set# normalize inputs from 0-255 to 0.0-1.0
X_train = X_train.astype('float32')#X_test = X_test.astype('float32')
X_train = X_train / 255.0#X_test = X_test / 255.0
# one hot encode outputs
y_train = np_utils.to_categorical(y_train)#y_test = np_utils.to_categorical(y_test)
num_classes = y_train.shape[1]# Create the model
model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape = (64, 64, 3), padding = 'same', activation = 'relu', kernel_constraint = maxnorm(3)))model.add(Dropout(0.2))
model.add(Conv2D(32, (3, 3), activation = 'relu', padding = 'same', kernel_constraint = maxnorm(3)))model.add(MaxPooling2D(pool_size = (2, 2)))
model.add(Flatten())
model.add(Dense(512, activation = 'relu', kernel_constraint = maxnorm(3)))
model.add(Dropout(0.5))
model.add(Dense(num_classes, activation = 'softmax'))# Compile model
epochs = 10
lrate = 0.01
decay = lrate/epochs
sgd = SGD(lr = lrate, momentum = 0.9, decay = decay, nesterov = False)
model.compile(loss = 'categorical_crossentropy', optimizer = sgd, metrics = ['accuracy'])
print(model.summary())#callbacks = [keras.callbacks.EarlyStopping(monitor = 'val_loss', min_delta = 0, patience = 0, verbose = 0, mode = 'auto')]
callbacks = [keras.callbacks.TensorBoard(log_dir='./logs', histogram_freq = 0, batch_size = 32, write_graph = True, write_grads = False, write_images = True, embeddings_freq = 0, embeddings_layer_names = None, embeddings_metadata = None)]# Fit the modelmodel.fit(X_train, y_train, epochs = epochs, batch_size = 32,shuffle = True,callbacks = callbacks)# Final evaluation of the model
scores = model.evaluate(X_train, y_train, verbose = 0)
print("Accuracy: %.2f%%" % (scores[1]*100))# serialize model to JSONx
model_json = model.to_json()
with open("model_face.json", "w") as json_file:json_file.write(model_json)# serialize weights to HDF5
model.save_weights("model_face.h5")
print("Saved model to disk")

The above line of code generates an output as shown below −

上面的代码行生成如下所示的输出-

翻译自: https://www.tutorialspoint.com/tensorflow/image_recognition_using_tensorflow.htm

使用TensorFlow进行图像识别相关推荐

  1. 基于 TensorFlow 的图像识别(R实现)

    提到机器学习,深度学习这些,大家都会立马想起Python.但R的实力也不容小觑.今天就用R来演示一个基于TensorFlow的图像识别的例子.如果你想运行这些代码,就必须先安装配置好TensorFlo ...

  2. 日常学习记录——pycharm+tensorflow简单图像识别

    日常学习记录--pycharm+tensorflow简单图像识别 写在前面 1 实验代码 2 实验结果 2.1 测试集的正确率 2.2 单个预测结果 2.3 集体预测结果 总结与标记 写在前面 使用p ...

  3. 深度学习入门:手把手教你用TensorFlow搭建图像识别模块

    之前和大家简单介绍了什么是神经网络(见我的文章:一句话告诉你什么是神经网络 ).那么今天再跟大家分享一些深度学习算法在图像识别上的应用.主要内容大概可以分为如下三个部分: ● 深度学习介绍: ● 神经 ...

  4. 深度学习篇之tensorflow(2) ---图像识别

    tensorflow处理图像识别 图像识别 图像识别的关键点及特点 卷积神经网络原理 视觉生物学研究 神经网络优势 卷积层 池化层 正则化层 卷积神经网络实例 样本数据读取 urlretrieve() ...

  5. 机器学习零基础?手把手教你用TensorFlow搭建图像识别系统

    [转] http://www.leiphone.com/news/201701/Y4uyEktkkwb5YhJM.html http://www.leiphone.com/news/201701/2t ...

  6. 教你用TensorFlow做图像识别

    弱者用泪水安慰自己,强者用汗水磨练自己. 上一篇文章里面讲了使用TensorFlow做手写数字图像识别,这篇文章算是它的进阶篇吧,在本篇文章中将会讲解如何使用TensorFlow识别多种类图片.本次使 ...

  7. matlab2017调用vgg19,TensorFlow vgg19 图像识别

    下载vgg预训练模型 https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg19_weights_tf_ ...

  8. 如何使用TensorFlow构建简单的图像识别系统(第2部分)

    by Wolfgang Beyer 沃尔夫冈·拜尔(Wolfgang Beyer) 如何使用TensorFlow构建简单的图像识别系统(第2部分) (How to Build a Simple Ima ...

  9. 从原理到代码:大牛教你如何用 TensorFlow 亲手搭建一套图像识别模块 | AI 研习社...

    自 2015 年 11 月首次发布以来,TensorFlow 凭借谷歌的强力支持,快速的更新和迭代,齐全的文档和教程,以及上手快且简单易用等诸多的优点,已经在图像识别.语音识别.自然语言处理.数据挖掘 ...

最新文章

  1. mybaits的模糊查询_mybatis模糊查询防止SQL注入(很详细)
  2. 【技术贴】虚拟机 VMware win7 win8网卡驱动下载 解决虚拟机不识别网卡没有本地连接...
  3. J2EE从servlet开始
  4. goland 远程调试 golang
  5. win10计算机恢复出厂设置,Windows 10 一键恢复出厂设置详细教程
  6. 如何判断 ios设备的类型(iphone,ipod,ipad)
  7. javascript中编码与解码的decodeURI()、decodeURIComponent()区别
  8. mysql并发插入死锁_MySQL: 并发replace into的死锁问题分析-阿里云开发者社区
  9. 【Java】springboot学习笔记二
  10. .net vue漂亮登录界面_基于 electron-vue 开发的音乐播放器「实践」
  11. 小学生python编程教程-python 小学生教程|怎么让一个小学生学会Python?
  12. 怎么用电脑操控自己的手机 怎样用电脑控制手机?
  13. 奶奶说标题不能起的太长要不然会有憨憨跟着读之Linux简述及常用命令
  14. 【K70例程】003读取LM75A温度传感器(I2C)
  15. 路由器关闭DHCP之后连接不到路由器设置界面?
  16. oracle 定时 analyze,Oracle工具:Analyze
  17. 北京政协:电子垃圾回收是亟待破解的难题
  18. 台式机dp接口_了解笔记本电脑的各种视频接口
  19. 解析USGS网站页面中的地震空间数据
  20. QT各种压缩包下载地址

热门文章

  1. NO.1—Python安装与环境配置
  2. RS232 小板测试
  3. 定位教程5---移动相机
  4. 【STL】unordered_set和unordered_map
  5. XP终端服务远程登录批处理(邪恶八进制blog)
  6. 学生信息管理系统(C语言版本+源码)
  7. Mysql中主键和外键和索引
  8. python try 嵌套_exception:如何在Python中安全地创建嵌套目录?
  9. 除权除息和复权复息的内容总结
  10. 机器人开发--常用仿真软件工具