Skip to content

Latest commit

 

History

History
52 lines (41 loc) · 5.45 KB

darknet.md

File metadata and controls

52 lines (41 loc) · 5.45 KB

Pretrained Darknet-53 for Image Classification

  • TensorFlow implementation of nature image classification using pre-trained Darknet-53 which is used as the feature extractor in YOLOv3.
  • This experiment is used to check whether the pre-trained model is correctly converted and loaded.
  • The original configuration of the Darknet-53 architecture can be found here.
  • The pre-trained model (.weights file) is first downloaded from YOLO website (Section Pre-Trained Models, Darknet53 448x448 link) and then convert to .npy file.

Implementation Details

  • The Darknet-53 model is defined in src/net/darknet.py. The network architecture is exact the same as the original configuration. The output layer is implemented as a 1x1 convolutional layer.
  • For each convolutional layer with stride = 2 (downsampling), instead of 'SAME' padding, the input is padded by 1 pixel in both width and height before and after the input content.
  • Leaky ReLU with alpha=0.1 and batch normalization are used for all convolutional layers except the output layer.
  • The convolutional bias only used in the output layer, as biases of other layers are absorbed in batch normalization.
  • An example of image classification using the pre-trained model is in experiment/darknet.

Download the pre-trained model

  • Download the pre-trained model darknet53_448.npy from here. This model is converted from the .weights file of Darknet-53 from here (Section 'Pre-Trained Models', Darknet53 448x448 link).
  • More details for converting models can be found here.

ImageNet classification

Go to experiment/, run

python darknet.py --data_dir DATA_DIR \
	--im_name PART_OF_IMAGE_NAME \
	--pretrained_path MODEL_PATH \
	--rescale SHORTER_SIDE
  • data_dir is the directory to put the test images. --im_name is the option for image names to be tested. The default setting is .jpg.
  • --pretrained_path is the path of pre-trained .npy file.
  • --rescale is the option for setting the shorter side of rescaled input image. The default setting is 256.
  • The output will be the top-5 class labels and probabilities.

Results

  • Top five predictions are shown. The probabilities are shown keeping two decimal places. Note that the pre-trained model are trained on ImageNet.
Data Source Image Result
COCO 1: probability: 1.00, label: brown bear, bruin, Ursus arctos
2: probability: 0.00, label: ice bear, polar bear, Ursus Maritimus, Thalarctos maritimus
3: probability: 0.00, label: American black bear, black bear, Ursus americanus, Euarctos americanus
4: probability: 0.00, label: chow, chow chow
5: probability: 0.00, label: sloth bear, Melursus ursinus, Ursus ursinus
COCO 1: probability: 0.97, label: street sign
2: probability: 0.02, label: traffic light, traffic signal, stoplight
3: probability: 0.00, label: pole
4: probability: 0.00, label: parking meter
5: probability: 0.00, label: mailbox, letter box
COCO 1: probability: 0.99, label: trolleybus, trolley coach, trackless trolley
2: probability: 0.01, label: school bus
3: probability: 0.00, label: passenger car, coach, carriage
4: probability: 0.00, label: fire engine, fire truck
5: probability: 0.00, label: minibus
COCO 1: probability: 0.36, label: plate
2: probability: 0.23, label: burrito
3: probability: 0.14, label: cheeseburger
4: probability: 0.11, label: Dungeness crab, Cancer magister
5: probability: 0.05, label: potpie
ImageNet 1: probability: 1.00, label: goldfish, Carassius auratus
2: probability: 0.00, label: tench, Tinca tinca
3: probability: 0.00, label: rock beauty, Holocanthus tricolor
4: probability: 0.00, label: anemone fish
5: probability: 0.00, label: puffer, pufferfish, blowfish, globefish
Self Collection 1: probability: 0.73, label: tabby, tabby cat
2: probability: 0.24, label: Egyptian cat
3: probability: 0.04, label: tiger cat
4: probability: 0.00, label: Siamese cat, Siamese
5: probability: 0.00, label: Persian cat
Self Collection 1: probability: 1.00, label: streetcar, tram, tramcar, trolley, trolley car
2: probability: 0.00, label: passenger car, coach, carriage
3: probability: 0.00, label: electric locomotive
4: probability: 0.00, label: trolleybus, trolley coach, trackless trolley
5: probability: 0.00, label: freight car

Reference code

Author

Qian Ge