ypwhs / dogs_vs_cats Goto Github PK
View Code? Open in Web Editor NEW猫狗大战
猫狗大战
如题
请问为什么提出的每一个.h5文件都是180多kb
用的是百度宠物狗识别数据100类,模型是inception-v3,resnet-50也试过结果都是这样:
loss: 0.0699 - acc: 0.9895 - val_loss: 0.1637 - val_acc: 0.9898
loss: 0.0676 - acc: 0.9892 - val_loss: 0.1607 - val_acc: 0.9899
loss: 0.0671 - acc: 0.9890 - val_loss: 0.1630 - val_acc: 0.9899
loss: 0.0670 - acc: 0.9888 - val_loss: 0.1620 - val_acc: 0.9898
loss: 0.0674 - acc: 0.9886 - val_loss: 0.1620 - val_acc: 0.9896
loss: 0.0677 - acc: 0.9884 - val_loss: 0.1584 - val_acc: 0.9898
loss: 0.0684 - acc: 0.9883 - val_loss: 0.1607 - val_acc: 0.9897
loss: 0.0685 - acc: 0.9882 - val_loss: 0.1637 - val_acc: 0.9896
但是实际检测错误率0.36以上~
作者您好,请问您能否分享一下ResNet50,Xception,InceptionV3,VGG19初始化的权重文件,我多次尝试都下载失败了,不胜感激。@ypwhs
您好,请问为什么测试文件不是按 1, 2, 3 排列,而是按1,10,100,1000,10000,10001?为什么前5个数是等比数列,而到了10000之后就是等差数列呢?为什么是用10000区分呢?
请问在keras2中,ImageDataGenerator().flow_from_generator.nb_sample不存在,应该如何解决?谢谢
首先很感谢作者的技术分享,但对您所设计的损失函数不能很好的理解,且对您的灵感源泉来自与logloss下无穷大问题这个链接也不能打开了,对于这个问题的修复不知道是否可以请您麻烦解释一下。谢谢
请问杨神,是VGG16 的preprocess_input会和generator的使用,会打乱RGB顺序 得到错误的特征吗吗?
培文哥,好像fit_generator里第二个steps参数是指的是batch个数,而文档里用的总的样本数(nb_batchbatch_size),相当于输出的数据是把源数据集用aug的方式扩充了batch_size倍,感觉steps写成nb_batch扩充倍数更容易读者理解。
您好,我是刚开始接触深度学习的学生,有很多很多不懂的东西。Python也是刚开始学,目前用的环境是
win10,keras2.0.4,python3.5。 pycharm作为IDE。我把代码拷贝下来都不能运行,而且我看代码也觉得有些地方不能理解,比如MODEL.fun_name,这样。在def write_gap(MODEL..,.,.)里MODEL是自己定的一个参数,他为什么会具有nb_sample,fuc_name呢。。。
因为要发论文的关系(确实很水。。但是前一年都在给导师做web上的项目去了,最近两个月才开始从机器学习入门开始。。)想做一个多分类的模型,之前只照着官网上猫狗的例子利用VGG16微调做了个4分类的,想做做其他实验,查了好多资料还是觉得什么都不懂,可能还是要从python基础开始学起,不然改模型真的太吃力了
如题,请问可否提供百度云或google drive的链接?
谢谢
为什么ResNet50没有用preprocess_input,而InceptionV3和Xception需要?
write_gap(ResNet50, (224, 224))
write_gap(InceptionV3, (299, 299), inception_v3.preprocess_input)
write_gap(Xception, (299, 299), xception.preprocess_input)
Hi, thanks for the great code. It is great for a beginner of Keras, like me. But I found some errors when I run the code. In gap.py, the terminal reports that "AttributeError: 'DirectoryIterator' object has no attribute 'nb_sample'". I wonder if it is due to the different versions of keras and is there any solutions to this? Thanks ahead of time!
我把几个模型组合起来,然后在输出端加上全连接层进行训练,但是loss在1.几就降不下去了,代码如下:
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0,1,2'
from keras.models import Model
from keras.callbacks import ReduceLROnPlateau
from keras.utils import plot_model
from keras.layers import *
from keras.applications import *
from keras import backend as K
from keras.preprocessing.image import *
import matplotlib.pyplot as plt
import h5py
base_models = locals()
use_models = {#ResNet50:{'preprocessing':None, 'size':(224, 224)},
InceptionV3:{'preprocessing':inception_v3.preprocess_input, 'size':(299, 299), 'device':'/gpu:0'},
Xception:{'preprocessing':xception.preprocess_input, 'size':(299, 299), 'device':'/gpu:1'},
InceptionResNetV2:{'preprocessing':inception_resnet_v2.preprocess_input, 'size':(299, 299), 'device':'/gpu:2'}
}
model_bottlenecks = []
input_tensor = Input((299, 299, 3))
for model, method in use_models.items():
width, height = method['size']
preprocessing = method['preprocessing']
device = method['device']
# input_tensor = Input((height, width, 3))
if preprocessing:
x = Lambda(preprocessing)(input_tensor)
with K.tf.device(device):
base_models[model.__name__] = model(input_tensor=x, weights='imagenet', include_top=False)
for layer in base_models[model.__name__] .layers:
layer.trainable = False
model_bottleneck = GlobalAveragePooling2D()(base_models[model.__name__].output)
model_bottlenecks.append(model_bottleneck)
with K.tf.device('/gpu:0'):
stack_bottleneck = concatenate(model_bottlenecks)
fc = Dropout(0.5)(stack_bottleneck)
fc = Dense(120, activation='softmax')(fc)
stack_model = Model(input_tensor, fc)
# plot_model(stack_model, to_file='model.png')
datagen = ImageDataGenerator(rotation_range=10,
width_shift_range=0.1,
height_shift_range=0.1,
zoom_range=0.1,
horizontal_flip=True,
vertical_flip=True
)
train_generator = datagen.flow_from_directory("raw_images", (299, 299), batch_size=64)
test_generator = datagen.flow_from_directory("test", (299, 299), batch_size=1)
stack_model.compile(optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'])
learning_rate_reduction = ReduceLROnPlateau(monitor='loss',
patience=3,
verbose=1,
factor=0.5,
min_lr=1e-8)
stack_model.fit_generator(train_generator,
steps_per_epoch=train_generator.n/64,
epochs=100,
verbose=1,
callbacks=[learning_rate_reduction])
stack_model.save_weights('stack_model.h5')
还有个编程问题,vgg和resnet的preprocess_input与inception的不同,直接加在lambda层会报错,这个要如何处理呢?
AttributeError: 'DirectoryIterator' object has no attribute 'nb_sample'
你好,因为现实的数据没有那么多的图片。我尝试把测试的数据集合变小(1000)个,然后重跑gap.ipynb 生成h5文件
很可惜预测的结果却很多错误。请问这是为什么呢
# coding: utf-8
# In[1]:
import os
import shutil
# In[2]:
SMALL_DATASET_COUNT = 1000
train_filenames = os.listdir('train')
train_cat = filter(lambda x: x[:3] == 'cat', train_filenames)
train_dog = filter(lambda x: x[:3] == 'dog', train_filenames)
test_file_dir = os.listdir('test')
test_filenames = filter(lambda x: int(x[:-4]) <= SMALL_DATASET_COUNT, test_file_dir)
# In[3]:
def rmrf_mkdir(dirname):
if os.path.exists(dirname):
shutil.rmtree(dirname)
os.mkdir(dirname)
# rmrf_mkdir('train2')
# os.mkdir('train2/cat')
# os.mkdir('train2/dog')
#
# rmrf_mkdir('test2')
# os.symlink('../test/', 'test2/test')
#
#
# for filename in train_cat:
# os.symlink('../../train/'+filename, 'train2/cat/'+filename)
#
# for filename in train_dog:
# os.symlink('../../train/'+filename, 'train2/dog/'+filename)
# In[ ]:
rmrf_mkdir('train-small-dataset')
os.mkdir('train-small-dataset/cat')
os.mkdir('train-small-dataset/dog')
file_count = 0
for filename in train_cat:
os.symlink('../../train/' + filename, 'train-small-dataset/cat/' + filename)
file_count += 1
if file_count >= SMALL_DATASET_COUNT:
break
file_count = 0
for filename in train_dog:
os.symlink('../../train/' + filename, 'train-small-dataset/dog/' + filename)
file_count += 1
if file_count >= SMALL_DATASET_COUNT:
break
rmrf_mkdir('test-small-dataset')
rmrf_mkdir('test-small-dataset/test')
file_count = 0
for filename in test_filenames:
os.symlink('../../test/' + filename, 'test-small-dataset/test/' + filename)
file_count += 1
if file_count >= SMALL_DATASET_COUNT:
break
ImageDataGenerator的作用不是为了增加数据量吗? 那么为什么最后保存的h5文件中训练集还是只有25000?
前面数据按照gap.py生成
Found 102945 images belonging to 30 classes.
Found 11456 images belonging to 30 classes.
我想改成30分类,x = Dense(30, activation='softmax')(x)
但是model.fit(X_train, y_train, batch_size=8, nb_epoch=8, validation_split=0.2)出错
错误:ValueError: Error when checking model target: expected dense_1 to have shape (None, 30) but got array with shape (102945, 1)
######3##
我该如何修改shape(102945,1)为(102945,30)
希望得到你的帮助!
谢谢
你好,首先感谢您的代码。我读了您的代码有很大启发。但是我自己运行除了问题。您的gap.ipynb最后导出的 h5 文件包括三个 numpy 数组:train (25000, 2048),test (12500, 2048),label (25000,)。而我得到的是train(399880,2048),test(199820,2048),label(25000,)。请问我是哪里出了问题。请求解答,谢谢!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.