-
大小: 4KB文件类型: .zip金币: 2下载: 0 次发布日期: 2021-06-17
- 语言: 其他
- 标签: Tensorflow
资源简介
基于Tensorflow下的cnn卷积神经网络实现图像的分类,Tensorflow

代码片段和文件信息
from skimage import iotransform
import glob
import os
import tensorflow as tf
import numpy as np
import time
#数据集地址
path=‘E:/data/datasets/flower_photos/‘
#模型保存地址
model_path=‘E:/data/model/flower/model.ckpt‘
#将所有的图片resize成100*100
w=100
h=100
c=3
#读取图片
def read_img(path):
cate=[path+x for x in os.listdir(path) if os.path.isdir(path+x)]
imgs=[]
labels=[]
for idxfolder in enumerate(cate):
for im in glob.glob(folder+‘/*.jpg‘):
#print(‘reading the images:%s‘%(im))
img=io.imread(im)
img=transform.resize(img(wh))
imgs.append(img)
labels.append(idx)
return np.asarray(imgsnp.float32)np.asarray(labelsnp.int32)
datalabel=read_img(path)
#打乱顺序
num_example=data.shape[0]
arr=np.arange(num_example)
np.random.shuffle(arr)
data=data[arr]
label=label[arr]
#将所有数据分为训练集和验证集
ratio=0.8
s=np.int(num_example*ratio)
x_train=data[:s]
y_train=label[:s]
x_val=data[s:]
y_val=label[s:]
#-----------------构建网络----------------------
#占位符
x=tf.placeholder(tf.float32shape=[Nonewhc]name=‘x‘)
y_=tf.placeholder(tf.int32shape=[None]name=‘y_‘)
def inference(input_tensor train regularizer):
with tf.variable_scope(‘layer1-conv1‘):
conv1_weights = tf.get_variable(“weight“[55332]initializer=tf.truncated_normal_initializer(stddev=0.1))
conv1_biases = tf.get_variable(“bias“ [32] initializer=tf.constant_initializer(0.0))
conv1 = tf.nn.conv2d(input_tensor conv1_weights strides=[1 1 1 1] padding=‘SAME‘)
relu1 = tf.nn.relu(tf.nn.bias_add(conv1 conv1_biases))
with tf.name_scope(“layer2-pool1“):
pool1 = tf.nn.max_pool(relu1 ksize = [1221]strides=[1221]padding=“VALID“)
with tf.variable_scope(“layer3-conv2“):
conv2_weights = tf.get_variable(“weight“[553264]initializer=tf.truncated_normal_initializer(stddev=0.1))
conv2_biases = tf.get_variable(“bias“ [64] initializer=tf.constant_initializer(0.0))
conv2 = tf.nn.conv2d(pool1 conv2_weights strides=[1 1 1 1] padding=‘SAME‘)
relu2 = tf.nn.relu(tf.nn.bias_add(conv2 conv2_biases))
with tf.name_scope(“layer4-pool2“):
pool2 = tf.nn.max_pool(relu2 ksize=[1 2 2 1] strides=[1 2 2 1] padding=‘VALID‘)
with tf.variable_scope(“layer5-conv3“):
conv3_weights = tf.get_variable(“weight“[3364128]initializer=tf.truncated_normal_initializer(stddev=0.1))
conv3_biases = tf.get_variable(“bias“ [128] initializer=tf.constant_initializer(0.0))
conv3 = tf.nn.conv2d(pool2 conv3_weights strides=[1 1 1 1] padding=‘SAME‘)
relu3 = tf.nn.relu(tf.nn.bias_add(conv3 conv3_biases))
with tf.name_scope(“layer6-pool3“):
pool3 = tf.nn.max_pool(relu3 ksize=[1 2 2 1] strides=[1 2 2 1] padding=‘VALID‘)
with tf.variable_scope(“layer7-conv4“):
conv4_weights = tf.get_v
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 10093 2018-01-04 21:41 新建文件夹\model_path.py
文件 1796 2018-01-08 11:06 新建文件夹\test.py
目录 0 2018-03-28 11:16 新建文件夹\
相关资源
- TensorFlow1.4 官方手册
- MSCNN_dehaze.rar
- 基于双向LSTM+tensorflow中文分词
- TensorFlow Machine Learning Cookbook+无码高清
- Hands-On Machine Learning with Scikit-Learn an
- TensorFlow 官方文档中文版高清无码PD
- 基于tensorflow的深度学习图像分类案例
- 基于Tensorflow多层神经网络的MNIST手写
- TensorFlow Tutorial
- TensorFlow_2.0快速应用指南英文.tar
- tensorflow图像风格迁移代码
- TensorFlow Machine Learning Cookbook
- Learning TensorFlow: A Guide to Building Deep
- tensorflow
- TensorFlow for Machine Intelligence 书籍源码
- 《Hands-On Machine Learning with Scikit-Learn
- Building Machine Learning Projects with Tensor
- TensorFlow Powerful Predictive Analytics with
- 北大tensorflow学习笔记
- LSTMandRNN.zip
- 使用TensorFlow搭建智能开发系统,自动
- Packt.TensorFlow.Machine.Learning.Cookbook.201
- tensorflow深度学习CNN智能识别车牌
- Tensorflow GNN实战.zip
- tensorflow从入门到精通
- 深度卷积生成对抗网络TensorFlow代码实
- TensorFlow_中文手册
- siamese mnist 孪生网络
- TensorFlow 中文文档 1.8 掘金 2018.5.19
- Tensorflow(一)训练自己的数据集——
评论
共有 条评论