-
大小: 84.53MB文件类型: .rar金币: 1下载: 0 次发布日期: 2022-09-08
- 语言: 其他
- 标签: tensorflow Inception-v3 迁移学习
资源简介
tensorflow利用Inception-v3实现迁移学习。加载已有的模型,作为新任务提取特征的操作,实现分类迁移。包含完整的代码和数据集
代码片段和文件信息
#photo地址:
#http://download.tensorflow.org/example_images/flower_photos.tgz
#Inception-v3模型
#https://storage.googleapis.com/download.tensorflow.org/models/inception_dec_2015.zip
import glob
import os.path
import random
import numpy as np
import tensorflow as tf
from tensorflow.python.platform import gfile
#Inception-v3模型瓶颈层得节点个数
BOTTLENECK_TENSOR_SIZE=2048
BOTTLENECK_TENSOR_NAME=‘pool_3/_reshape:0‘
JPEG_DATA_TENSOR_NAME=‘DecodeJpeg/contents:0‘
MODEL_DIR=‘C:/Users/casgj/PycharmProjects/CNN/inception_dec_2015‘
MODEL_FILE=‘tensorflow_inception_graph.pb‘
CACHE_DIR=‘C:/Users/casgj/PycharmProjects/CNN/bottleneck‘
INPUT_DATA=‘C:/Users/casgj/PycharmProjects/CNN/flower_photos‘
#验证得数据百分比
VALIDATION_PERCENTAGE=10
#测试得数据百分比
TEST_PERCENTAGE=10
#定义神经网络得设置
LEARNING_RATE=0.01
STEPS=4000
BATCH=100
#从数据文件夹读取所有得图片列表并按训练、验证、测试数据分开
def create_image_lists(testing_percentage validation_percentage):
result = {}
sub_dirs = [x[0] for x in os.walk(INPUT_DATA)]
is_root_dir = True
for sub_dir in sub_dirs:
if is_root_dir:
is_root_dir = False
continue
extensions = [‘jpg‘ ‘jpeg‘ ‘JPG‘ ‘JPEG‘]
file_list = []
dir_name = os.path.basename(sub_dir)
for extension in extensions:
file_glob = os.path.join(INPUT_DATA dir_name ‘*.‘ + extension)
file_list.extend(glob.glob(file_glob))
if not file_list:
continue
label_name = dir_name.lower()
# 初始化
training_images = []
testing_images = []
validation_images = []
for file_name in file_list:
base_name = os.path.basename(file_name)
# 随机划分数据
chance = np.random.randint(100) #产生一个<100得正整数
if chance < validation_percentage:
validation_images.append(base_name)
elif chance < (testing_percentage + validation_percentage):
testing_images.append(base_name)
else:
training_images.append(base_name)
result[label_name] = {
‘dir‘: dir_name
‘training‘: training_images
‘testing‘: testing_images
‘validation‘: validation_images
}
return result
#获取给定类别category中index图片的地址
def get_image_path(image_listsimage_dirlabel_nameindexcategory):
label_lists=image_lists[label_name]
category_list=label_lists[category]
mod_index=index% len(category_list)
base_name=category_list[mod_index]
sub_dir=label_lists[‘dir‘]
full_path=os.path.join(image_dirsub_dirbase_name)
return full_path
def get_bottleneck_path(image_listslabel_nameindexcategory):
return get_image_path(image_listsCACHE_DIR
label_nameindexcategory)+‘.txt‘
def run_bottleneck_on_image(sessimage_dataimage_data_tensorbottleneck_tensor):
bottleneck_values=sess.run(bottleneck_te
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 88631107 2018-10-01 12:03 inception_dec_2015.zip
文件 10466 2018-10-02 15:54 迁移学习.py
----------- --------- ---------- ----- ----
88641573 2
相关资源
- TensorFlow实战_黄文坚.pdf
- tensorflow win10 编译教程
- tensorflow-1.10.1-cp36-cp36m-linux_aarch64.whl
- fer2013.tar.gz
- 基于TensorFlow的手写中文识别
- 676624《强化学习精要核心算法与Tens
- OpenCV、TensorFlow安装库及安装方法
- cusolver64_100.dll,cusparse64_100.dll
- tensorflow-1.11.0-cp35-none-linux_aarch64.whl
- 支持CUDA10的tensorflow-gpu轮子
- tensorflow1.10.0-cp36win-gpu版
- hands on machine learning with scikit learn an
- tensorflow-1.0.1-cp27-cp27mu-linux_aarch64.whl
- Tensorflow实战Google深度学习框架.zip
- tensorflow_inception_graph.pb
- 基于tensorflow的卷积神经网络数字手写
- Scikit-Learn与TensorFlow机器学习实用指南
- Scikit-Learn与TensorFlow机器学习实用指南
- 21个项目玩转深度学习全部资源---基于
- 21个项目玩转深度学习基于TensorFlow的
-
深度学习一起玩转Tensorla
yer - 25本Deep Learning英文PDF电子书清晰无水
- cudnn-9.2-windows10-x64-v7.1
- TensorFlow实战_黄文坚 高清完整书籍和
- tensorflow-gpu-2.0.0rc2-cp36-cp36m-win_amd64.w
- Hands-On Machine Learning with Scikit-Learn an
- Hands-On Machine Learning with Scikit-Learn &
- 基于和特征的迁移学习算法研究_戴文
- 《机器学习实战:基于Scikit-Learn和T
- OpenCV4.0 cmake后生成的库文件,包含c
评论
共有 条评论