资源简介
keras-finetuning, 使用你自己的数据集训练基于InceptionV3的图像分类器 使用你自己的数据集训练InceptionV3-based图像分类器基于在的新集合中的微调( InceptionV3 ),在 https://keras.io/applications/中的例子依赖项最新的( 来自源的> =1.0
代码片段和文件信息
# This should be completely refactored shares a lot of code with train.py
import sys
from collections import defaultdict
import numpy as np
# It‘s very important to put this import before keras
# as explained here: Loading tensorflow before scipy.misc seems to cause imread to fail #1541
# https://github.com/tensorflow/tensorflow/issues/1541
import scipy.misc
from keras.utils import np_utils
import dataset
import net
np.random.seed(1337)
n = 224
batch_size = 128
data_directory = sys.argv[1:]
X y tags = dataset.dataset(data_directory n)
nb_classes = len(tags)
sample_count = len(y)
train_size = sample_count * 4 // 5
X_train = X[:train_size]
y_train = y[:train_size]
Y_train = np_utils.to_categorical(y_train nb_classes)
X_test = X[train_size:]
y_test = y[train_size:]
Y_test = np_utils.to_categorical(y_test nb_classes)
def evaluate(model vis_filename=None):
Y_pred = model.predict(X_test batch_size=batch_size)
y_pred = np.argmax(Y_pred axis=1)
accuracy = float(np.sum(y_test==y_pred)) / len(y_test)
print “accuracy:“ accuracy
confusion = np.zeros((nb_classes nb_classes) dtype=np.int32)
for (predicted_index actual_index image) in zip(y_pred y_test X_test):
confusion[predicted_index actual_index] += 1
print “rows are predicted classes columns are actual classes“
for predicted_index predicted_tag in enumerate(tags):
print predicted_tag[:7]
for actual_index actual_tag in enumerate(tags):
print “\t%d“ % confusion[predicted_index actual_index]
print
if vis_filename is not None:
bucket_size = 10
image_size = n // 4 # right now that‘s 56
vis_image_size = nb_classes * image_size * bucket_size
vis_image = 255 * np.ones((vis_image_size vis_image_size 3) dtype=‘uint8‘)
example_counts = defaultdict(int)
for (predicted_tag actual_tag normalized_image) in zip(y_pred y_test X_test):
example_count = example_counts[(predicted_tag actual_tag)]
if example_count >= bucket_size**2:
continue
image = dataset.reverse_preprocess_input(normalized_image)
image = image.transpose((1 2 0))
image = scipy.misc.imresize(image (image_size image_size)).astype(np.uint8)
tilepos_x = bucket_size * predicted_tag
tilepos_y = bucket_size * actual_tag
tilepos_x += example_count % bucket_size
tilepos_y += example_count // bucket_size
pos_x pos_y = tilepos_x * image_size tilepos_y * image_size
vis_image[pos_y:pos_y+image_size pos_x:pos_x+image_size :] = image
example_counts[(predicted_tag actual_tag)] += 1
vis_image[::image_size * bucket_size :] = 0
vis_image[: ::image_size * bucket_size] = 0
scipy.misc.imsave(vis_filename vis_image)
model tags_from_model = net.load(“model“)
assert tags == tags_from_model
net.compile(model)
evalua
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-09-13 21:12 keras-finetuning-master\
文件 3855 2016-09-13 21:12 keras-finetuning-master\README.md
文件 3028 2016-09-13 21:12 keras-finetuning-master\classify.py
文件 793 2016-09-13 21:12 keras-finetuning-master\collect-apple-photos.sh
文件 1886 2016-09-13 21:12 keras-finetuning-master\collect_apple_photos.py
文件 2202 2016-09-13 21:12 keras-finetuning-master\dataset.py
文件 930127 2016-09-13 21:12 keras-finetuning-master\haarcascade_frontalface_default.xm
文件 1852 2016-09-13 21:12 keras-finetuning-master\net.py
文件 911 2016-09-13 21:12 keras-finetuning-master\osx-install.sh
文件 6073 2016-09-13 21:12 keras-finetuning-master\train.py
文件 2301 2016-09-13 21:12 keras-finetuning-master\webcam.py
相关资源
- git-plugin Jenkins的Git插件.zip
- 几十个开源项目28G设计资料,适用于
- Pdflibnet.dll 64bit
- ntru 加密算法开源C实现
- iec61850 开源实现
- TLSF开源算法
- arduino开源平衡车源代码
- 微信小程序源码——《出发吧一起》
- 共享名片小程序4.7.12 全开源版含前后
- 开源的超级玛丽源代码
- CORBA开源测试工具.pdf
- 开源3D游戏引擎 HXEngine
- 进销存无保留开源
- 开源三轴无刷云台算法STM32程序带注释
- 明日物流管理系统
- Birt与Echarts集成.pdf
- 虹膜识别开源代码
-
Eclipse + CDT + YAGARTO + J-li
nk,STM32开源 - 开源的HDLC解析程序
- Simple Bgc 源码 基于STM32的三轴增稳云台
- DQN-Atari-Tensorflow 在Tensorflow中,使用深
- 开源老虎微信淘宝客v5.99.34+代理2.99
- 安装risc-V的rocket的环境,零基础
- SOEM函数解读Ethercat主站开源 主要函
- 开源CNC控制器设计
- 开源三轴无刷云台自稳算法
- 开源云台电路图
- 微信群裂变神器 wxlm_groupfission 1.6.4全
- NPOI开源的.NET读写Excel、WORD等文档的类
- 《开源软核处理器OpenRisc的SOPC设计》
评论
共有 条评论