GithubHelp home page GithubHelp logo

xup5 / imagenet_resnet_tensorflow2.0 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from apm5/imagenet_resnet_tensorflow2.0

0.0 0.0 0.0 4.39 MB

Train ResNet on ImageNet in Tensorflow 2.0; ResNet 在ImageNet上完整训练代码

Python 100.00%

imagenet_resnet_tensorflow2.0's Introduction

Train ResNet on ImageNet in Tensorflow 2.0

Accuracy

Network Center crop @ top-1 10-crop @ top-1
ResNet-18 69.15% 71.60%
ResNet-50 75.96% 77.72%

Meet the accuracy in Deep Residual Learning for Image Recognition.

The weights is provided.

Link: https://pan.baidu.com/s/1nwvkt3Ei5Hp5Pis35cBSmA

Code: y4wo

Requirements

Python version: 3.5.1

Packages:

  • Tensorflow 2.0.0
  • numpy
  • opencv-python
  • tqdm

Dataset

The ImageNet data can be downloaded from http://www.image-net.org/.

Or you can contact me for a download link of Baidu Netdisk.

If you want to train your own data, please modify all the files in data/ and config.py.

Usage

Prepare

All training settings are in config.py. You can change the log_file and save_weight_file to set save path.

To use default config, you should create the directory before training.

mkdir result
mkdir result/log
mkdir result/weight

For the other parameters in config.py, it is not suggested to change them unless you know what you are doing.

Model

Various versions of ResNet, which is 18, 34, 50, 101 and 152, are implemented in Tensorflow 2.0

from model.ResNet import ResNet
model = ResNet(50)

Or you can import the model in keras applications

from tensorflow.keras.applications.resnet50 import ResNet50
model = ResNet50(weights=None)

Set model in train.py, which defaults to ResNet-50 v2.

Training

python3 train.py

My experimental environment is

  • i7-6850K @ 3.6GHz
  • TITAN Xp, 12GB

For ResNet-50, average training speed is 2 iterations per second. So it will take about 3 days to complete the training, which is 50 epochs.

If Allocator (GPU_0_bfc) ran out of memory trying to allocate..., please reduce the batch size.

Test

Set the load_weight_file in config.py.

In test code, images are resized such that the shorter side is 256. Then crop the 224*224 area as the input.

python3 test.py is center crop test.

python3 test_10_crop.py is standard 10-crop test mentioned in Deep Residual Learning for Image Recognition.

python3 test_single_image.py is single image test. Set the image path and model path before run it. The final output is the category name and confidence.

For example, the input image is

input image

and the output is


----------------------------------------
image: ILSVRC2012_val_00000321.JPEG
classification result:computer_keyboard
confidence:0.7444
----------------------------------------

More

Basic tutorial for tensorflow 2.0: https://github.com/Apm5/tensorflow_2.0_tutorial

For chinese friends: 我有一个知乎专栏,里面有中文版本的教程

Contact me: [email protected]

imagenet_resnet_tensorflow2.0's People

Contributors

apm5 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.