Preparations
Original Model Preparation
ResNet-50 is a deep residual network competent for CIFAR-10 and ImageNet-1K classification tasks.
Click here to obtain the original ResNet script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | ├── r1 // Original model directory. │ ├── resnet // ResNet main directory. │ ├── __init__.py │ ├── imagenet_main.py // Script for training the network based on the ImageNet dataset. │ ├── imagenet_preprocessing.py // ImageNet preprocessing module. │ ├── resnet_model.py // ResNet model file. │ ├── resnet_run_loop.py // Data input processing and execution iteration (training, validation, and test). │ ├── README.md // Project description file. │ ├── utils │ ├── export.py // Data receive functions, which define the parameter formats that the exported model can respond to. ├── utils │ ├── flags │ ├── core.py // Public APIs including the parameter definition. │ ├── logs │ ├── hooks_helper.py // Tool used for custom model testing and training, such as the function for calculating the number of steps per second, and the function of capturing CPU/GPU analysis information. │ ├── logger.py // Log tool. │ ├── misc │ ├── distribution_utils.py // Auxiliary functions used for running models in distributed mode. │ ├── model_helpers.py // Functions that can be called by the model, such as a function that stops the model. |
Dataset Preparation
- Prepare a dataset.
- Obtain the dataset.
This sample uses the ImageNet 2012 dataset as an example. Download the dataset from https://www.image-net.org/. Validate the dataset package and upload it to the training environment.
- The dataset directory is organized as follows (the dataset directory is /data/dataset/ in this example):
1 2 3 4
├──imagenet2012 │ ├──ILSVRC2012_img_train.tar │ ├──ILSVRC2012_img_val.tar │ ├──ILSVRC2012_bbox_train_v2.tar.gz
- Create and run the training script. Create the train, val, bbox, and imagenet_tf directories respectively, and decompress the train, val, and bbox dataset packages to the corresponding directories.
- Create and open the prepare_dataset.sh script.
vim prepare_dataset.sh
- Add the following commands to the script:
1 2 3 4 5
#!/bin/bash mkdir -p train val bbox imagenet_tf tar -xvf ILSVRC2012_img_train.tar -C train/ tar -xvf ILSVRC2012_img_val.tar -C val/ tar -xvf ILSVRC2012_bbox_train_v2.tar.gz -C bbox/
- Run the :wq! command to save the file and exit.
- Run the following command to run the script:
- Create and open the prepare_dataset.sh script.
- Check the dataset directory. In this example, the dataset directory is /data/dataset/.
1 2 3 4 5 6 7
├──imagenet2012 │ ├──ILSVRC2012_img_train.tar │ ├──ILSVRC2012_img_val.tar │ ├──ILSVRC2012_bbox_train_v2.tar.gz │ ├──bbox/ │ ├──train/ │ ├──val/
- Obtain the dataset.
- Convert the dataset to the TFRecord format.
- Download the source package.
- Go to the datasets directory of the source package and preprocess validation data.
cd models-master/research/slim/datasets/
python preprocess_imagenet_validation_data.py /data/dataset/imagenet2012/val/ imagenet_2012_validation_synset_labels.txt # Preprocess the validation data.
- Convert XML files to a CSV file.
python process_bounding_boxes.py /data/dataset/imagenet2012/bbox/ imagenet_lsvrc_2015_synsets.txt | sort > imagenet_2012_bounding_boxes.csv
- Convert the ImageNet dataset to the TFRecord format.
python build_imagenet_data.py --output_directory=/data/dataset/imagenet2012/imagenet_tf --train_directory=/data/dataset/imagenet2012/train --validation_directory=/data/dataset/imagenet2012/val
- Inspect the dataset after conversion.
1 2 3 4 5 6 7 8 9 10
├─ imagenet2012 ├─——imagenet_tf │ ├──train-00000-of-01024 │ ├──train-00001-of-01024 │ ├──train-00002-of-01024 │ ... │ ├──validation-00000-of-00128 │ ├──validation-00001-of-00128 │ ├──validation-00002-of-00128 │ ...
