Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using fine-tuned model in Kaggle Dog competition #226

Merged
merged 7 commits into from
Mar 29, 2018

Conversation

hetong007
Copy link
Contributor

By setting epoch=30, one can achieve score ~0.49 on the leaderboard.

@astonzhang Please review.

for aug in auglist:
im = aug(im)
# 将数据格式从"高*宽*通道"改为"通道*高*宽"。
im = nd.transpose(im, (2,0,1))
return (im, nd.array([label]).asscalar().astype('float32'))

def transform_test(data, label):
im = image.imresize(data.astype('float32') / 255, 96, 96)
im = image.imresize(data.astype('float32') / 255, 256, 256)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to resize to 256, 256 for test? Can we do the following:

im = data.astype('float32') / 255 

before invoking image.imresize?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a ImageNet benchmarking standard, we can omit it here for simplicity.

我们这里使用了[ResNet-18](resnet-gluon.md)模型。我们使用[hybridizing](../chapter_gluon-advances/hybridize.md)来提升执行效率。
我们这里借助[迁移学习](fine-tuning.md)的思想,调用`Gluon`中经过预训练的[ResNet-34](resnet-gluon.md)模型,并通过微调在新数据集上进行训练。

这里,我们使用与前述教程略微不同的迁移学习方法。在新的训练数据与预训练数据相似的情况下,我们认为原有特征是可重用的。基于这个原因,在一个预训练好的新模型上,我们可以不去改变原已训练好的权重,而是在原网络结构上新加一个小的输出网络。这样能够节省后向传播的时间,也能避免了在特征层上储存梯度所需要的内存空间。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The audience are mostly users without any background on deep learning. Thus, we need to make it even clearer. For instance, ResNet-34 is pre-trained on ImageNet. Our problem is a subset of ImageNet. So we can apply this pre-trained model.

For "而是在原网络结构上新加一个小的输出网络", we should explicitly say that parameters of this layer need to be trained.


注意,我们在之前定义的数据预处理函数用了ImageNet数据集上的均值和标准差做标准化,这样才能保证预训练模型能够捕捉正确的数据特征。

![](../img/fix_feature_fine_tune.png)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In images, pretrained -> pre-trained

print('Block %d output: %s'%(i+1, out.shape))
return out

from mxnet.gluon.model_zoo import vision as models

def get_net(ctx):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Within get_net, we need to add comments to explain, such as line by line (if necessary).

@hetong007
Copy link
Contributor Author

@astonzhang PR is updated accordingly.

@astonzhang
Copy link
Member

LGTM. Just let me know when you got the performance after 30 epochs.

@hetong007
Copy link
Contributor Author

The full training process uses roughly 4GB GPU ram with batch=128. The accuracy is at 0.446 on the leaderboard.

@astonzhang
Copy link
Member

Good. Thanks!

@astonzhang astonzhang merged commit 998ae6c into d2l-ai:master Mar 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants