Skip to content

Commit

Permalink
initial check-in of DetectNet training guide
Browse files Browse the repository at this point in the history
  • Loading branch information
dusty-nv committed May 16, 2017
1 parent 36aff62 commit 05b5742
Show file tree
Hide file tree
Showing 15 changed files with 2,864 additions and 21 deletions.
269 changes: 248 additions & 21 deletions README.md

Large diffs are not rendered by default.

Binary file added data/images/dog_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,548 changes: 2,548 additions & 0 deletions data/networks/detectnet.prototxt

Large diffs are not rendered by default.

Binary file added docs/images/detectnet-digits-custom-network.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/detectnet-digits-infer-dog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/detectnet-digits-model-dog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/detectnet-digits-new-dataset-dog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/detectnet-digits-new-model-dog.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/detectnet-tensorRT-airplane-0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/detectnet-tensorRT-bottle-0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/detectnet-tensorRT-dog-0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/detectnet-tensorRT-dog-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 68 additions & 0 deletions tools/coco2kitti.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""coco2kitti.py: Converts MS COCO annotation files to
Kitti format bounding box label files
__author__ = "Jon Barker"
"""

import os
from pycocotools.coco import COCO

def coco2kitti(catNms, annFile):

# initialize COCO api for instance annotations
coco = COCO(annFile)

# Create an index for the category names
cats = coco.loadCats(coco.getCatIds())
cat_idx = {}
for c in cats:
cat_idx[c['id']] = c['name']

for img in coco.imgs:

# Get all annotation IDs for the image
catIds = coco.getCatIds(catNms=catNms)
annIds = coco.getAnnIds(imgIds=[img], catIds=catIds)

# If there are annotations, create a label file
if len(annIds) > 0:
# Get image filename
img_fname = coco.imgs[img]['file_name']
# open text file
with open('./labels/' + img_fname.split('.')[0] + '.txt','w') as label_file:
anns = coco.loadAnns(annIds)
for a in anns:
bbox = a['bbox']
# Convert COCO bbox coords to Kitti ones
bbox = [bbox[0], bbox[1], bbox[2] + bbox[0], bbox[3] + bbox[1]]
bbox = [str(b) for b in bbox]
catname = cat_idx[a['category_id']]
# Format line in label file
# Note: all whitespace will be removed from class names
out_str = [catname.replace(" ","")
+ ' ' + ' '.join(['0']*3)
+ ' ' + ' '.join([b for b in bbox])
+ ' ' + ' '.join(['0']*8)
+'\n']
label_file.write(out_str[0])

if __name__ == '__main__':

# These settings assume this script is in the annotations directory
dataDir = '..'
dataType = 'train2014'
annFile = '%s/annotations/instances_%s.json' % (dataDir, dataType)

# If this list is populated then label files will only be produced
# for images containing the listed classes and only the listed classes
# will be in the label file
# EXAMPLE:
#catNms = ['person', 'dog', 'skateboard']
catNms = []

# Check if a labels file exists and, if not, make one
# If it exists already, exit to avoid overwriting
if os.path.isdir('./labels'):
print('Labels folder already exists - exiting to prevent badness')
else:
os.mkdir('./labels')
coco2kitti(catNms, annFile)

0 comments on commit 05b5742

Please sign in to comment.