Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

216 lignes
5.9KB

  1. # PASCAL VOC dataset http://host.robots.ox.ac.uk/pascal/VOC/
  2. # Download command: bash ./data/get_voc.sh
  3. # Train command: python train.py --data voc.yaml
  4. # Default dataset location is next to /yolov5:
  5. # /parent_folder
  6. # /VOC
  7. # /yolov5
  8. start=`date +%s`
  9. # handle optional download dir
  10. if [ -z "$1" ]
  11. then
  12. # navigate to ~/tmp
  13. echo "navigating to ../tmp/ ..."
  14. mkdir -p ../tmp
  15. cd ../tmp/
  16. else
  17. # check if is valid directory
  18. if [ ! -d $1 ]; then
  19. echo $1 "is not a valid directory"
  20. exit 0
  21. fi
  22. echo "navigating to" $1 "..."
  23. cd $1
  24. fi
  25. echo "Downloading VOC2007 trainval ..."
  26. # Download the data.
  27. curl -LO http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar
  28. echo "Downloading VOC2007 test data ..."
  29. curl -LO http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar
  30. echo "Done downloading."
  31. # Extract data
  32. echo "Extracting trainval ..."
  33. tar -xf VOCtrainval_06-Nov-2007.tar
  34. echo "Extracting test ..."
  35. tar -xf VOCtest_06-Nov-2007.tar
  36. echo "removing tars ..."
  37. rm VOCtrainval_06-Nov-2007.tar
  38. rm VOCtest_06-Nov-2007.tar
  39. end=`date +%s`
  40. runtime=$((end-start))
  41. echo "Completed in" $runtime "seconds"
  42. start=`date +%s`
  43. # handle optional download dir
  44. if [ -z "$1" ]
  45. then
  46. # navigate to ~/tmp
  47. echo "navigating to ../tmp/ ..."
  48. mkdir -p ../tmp
  49. cd ../tmp/
  50. else
  51. # check if is valid directory
  52. if [ ! -d $1 ]; then
  53. echo $1 "is not a valid directory"
  54. exit 0
  55. fi
  56. echo "navigating to" $1 "..."
  57. cd $1
  58. fi
  59. echo "Downloading VOC2012 trainval ..."
  60. # Download the data.
  61. curl -LO http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar
  62. echo "Done downloading."
  63. # Extract data
  64. echo "Extracting trainval ..."
  65. tar -xf VOCtrainval_11-May-2012.tar
  66. echo "removing tar ..."
  67. rm VOCtrainval_11-May-2012.tar
  68. end=`date +%s`
  69. runtime=$((end-start))
  70. echo "Completed in" $runtime "seconds"
  71. cd ../tmp
  72. echo "Spliting dataset..."
  73. python3 - "$@" <<END
  74. import xml.etree.ElementTree as ET
  75. import pickle
  76. import os
  77. from os import listdir, getcwd
  78. from os.path import join
  79. sets=[('2012', 'train'), ('2012', 'val'), ('2007', 'train'), ('2007', 'val'), ('2007', 'test')]
  80. classes = ["aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"]
  81. def convert(size, box):
  82. dw = 1./(size[0])
  83. dh = 1./(size[1])
  84. x = (box[0] + box[1])/2.0 - 1
  85. y = (box[2] + box[3])/2.0 - 1
  86. w = box[1] - box[0]
  87. h = box[3] - box[2]
  88. x = x*dw
  89. w = w*dw
  90. y = y*dh
  91. h = h*dh
  92. return (x,y,w,h)
  93. def convert_annotation(year, image_id):
  94. in_file = open('VOCdevkit/VOC%s/Annotations/%s.xml'%(year, image_id))
  95. out_file = open('VOCdevkit/VOC%s/labels/%s.txt'%(year, image_id), 'w')
  96. tree=ET.parse(in_file)
  97. root = tree.getroot()
  98. size = root.find('size')
  99. w = int(size.find('width').text)
  100. h = int(size.find('height').text)
  101. for obj in root.iter('object'):
  102. difficult = obj.find('difficult').text
  103. cls = obj.find('name').text
  104. if cls not in classes or int(difficult)==1:
  105. continue
  106. cls_id = classes.index(cls)
  107. xmlbox = obj.find('bndbox')
  108. b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text))
  109. bb = convert((w,h), b)
  110. out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')
  111. wd = getcwd()
  112. for year, image_set in sets:
  113. if not os.path.exists('VOCdevkit/VOC%s/labels/'%(year)):
  114. os.makedirs('VOCdevkit/VOC%s/labels/'%(year))
  115. image_ids = open('VOCdevkit/VOC%s/ImageSets/Main/%s.txt'%(year, image_set)).read().strip().split()
  116. list_file = open('%s_%s.txt'%(year, image_set), 'w')
  117. for image_id in image_ids:
  118. list_file.write('%s/VOCdevkit/VOC%s/JPEGImages/%s.jpg\n'%(wd, year, image_id))
  119. convert_annotation(year, image_id)
  120. list_file.close()
  121. END
  122. cat 2007_train.txt 2007_val.txt 2012_train.txt 2012_val.txt > train.txt
  123. cat 2007_train.txt 2007_val.txt 2007_test.txt 2012_train.txt 2012_val.txt > train.all.txt
  124. python3 - "$@" <<END
  125. import shutil
  126. import os
  127. os.system('mkdir ../VOC/')
  128. os.system('mkdir ../VOC/images')
  129. os.system('mkdir ../VOC/images/train')
  130. os.system('mkdir ../VOC/images/val')
  131. os.system('mkdir ../VOC/labels')
  132. os.system('mkdir ../VOC/labels/train')
  133. os.system('mkdir ../VOC/labels/val')
  134. import os
  135. print(os.path.exists('../tmp/train.txt'))
  136. f = open('../tmp/train.txt', 'r')
  137. lines = f.readlines()
  138. for line in lines:
  139. #print(line.split('/')[-1][:-1])
  140. line = "/".join(line.split('/')[2:])
  141. #print(line)
  142. if (os.path.exists("../" + line[:-1])):
  143. os.system("cp ../"+ line[:-1] + " ../VOC/images/train")
  144. print(os.path.exists('../tmp/train.txt'))
  145. f = open('../tmp/train.txt', 'r')
  146. lines = f.readlines()
  147. for line in lines:
  148. #print(line.split('/')[-1][:-1])
  149. line = "/".join(line.split('/')[2:])
  150. line = line.replace('JPEGImages', 'labels')
  151. line = line.replace('jpg', 'txt')
  152. #print(line)
  153. if (os.path.exists("../" + line[:-1])):
  154. os.system("cp ../"+ line[:-1] + " ../VOC/labels/train")
  155. print(os.path.exists('../tmp/2007_test.txt'))
  156. f = open('../tmp/2007_test.txt', 'r')
  157. lines = f.readlines()
  158. for line in lines:
  159. #print(line.split('/')[-1][:-1])
  160. line = "/".join(line.split('/')[2:])
  161. if (os.path.exists("../" + line[:-1])):
  162. os.system("cp ../"+ line[:-1] + " ../VOC/images/val")
  163. print(os.path.exists('../tmp/2007_test.txt'))
  164. f = open('../tmp/2007_test.txt', 'r')
  165. lines = f.readlines()
  166. for line in lines:
  167. #print(line.split('/')[-1][:-1])
  168. line = "/".join(line.split('/')[2:])
  169. line = line.replace('JPEGImages', 'labels')
  170. line = line.replace('jpg', 'txt')
  171. #print(line)
  172. if (os.path.exists("../" + line[:-1])):
  173. os.system("cp ../"+ line[:-1] + " ../VOC/labels/val")
  174. END
  175. rm -rf ../tmp # remove temporary directory
  176. echo "VOC download done."