Switch to unified view

a b/data/scripts/get_imagenet.sh
1
#!/bin/bash
2
# YOLOv5 🚀 by Ultralytics, AGPL-3.0 license
3
# Download ILSVRC2012 ImageNet dataset https://image-net.org
4
# Example usage: bash data/scripts/get_imagenet.sh
5
# parent
6
# ├── yolov5
7
# └── datasets
8
#     └── imagenet  ← downloads here
9
10
# Arguments (optional) Usage: bash data/scripts/get_imagenet.sh --train --val
11
if [ "$#" -gt 0 ]; then
12
  for opt in "$@"; do
13
    case "${opt}" in
14
    --train) train=true ;;
15
    --val) val=true ;;
16
    esac
17
  done
18
else
19
  train=true
20
  val=true
21
fi
22
23
# Make dir
24
d='../datasets/imagenet' # unzip directory
25
mkdir -p $d && cd $d
26
27
# Download/unzip train
28
if [ "$train" == "true" ]; then
29
  wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_img_train.tar # download 138G, 1281167 images
30
  mkdir train && mv ILSVRC2012_img_train.tar train/ && cd train
31
  tar -xf ILSVRC2012_img_train.tar && rm -f ILSVRC2012_img_train.tar
32
  find . -name "*.tar" | while read NAME; do
33
    mkdir -p "${NAME%.tar}"
34
    tar -xf "${NAME}" -C "${NAME%.tar}"
35
    rm -f "${NAME}"
36
  done
37
  cd ..
38
fi
39
40
# Download/unzip val
41
if [ "$val" == "true" ]; then
42
  wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_img_val.tar # download 6.3G, 50000 images
43
  mkdir val && mv ILSVRC2012_img_val.tar val/ && cd val && tar -xf ILSVRC2012_img_val.tar
44
  wget -qO- https://raw.githubusercontent.com/soumith/imagenetloader.torch/master/valprep.sh | bash # move into subdirs
45
fi
46
47
# Delete corrupted image (optional: PNG under JPEG name that may cause dataloaders to fail)
48
# rm train/n04266014/n04266014_10835.JPEG
49
50
# TFRecords (optional)
51
# wget https://raw.githubusercontent.com/tensorflow/models/master/research/slim/datasets/imagenet_lsvrc_2015_synsets.txt