Skip to content

Instantly share code, notes, and snippets.

@SeaOfOcean
Created January 15, 2018 08:13
Show Gist options
  • Save SeaOfOcean/0b4cc8bcc2a8b1961bb29c9d3f803901 to your computer and use it in GitHub Desktop.
Save SeaOfOcean/0b4cc8bcc2a8b1961bb29c9d3f803901 to your computer and use it in GitHub Desktop.
import os
from os.path import isfile
import random
annots = os.listdir("annotations")
random.shuffle(annots)
test_len = int(len(annots) * 0.1)
train_data = annots[test_len:]
test_data = annots[:test_len]
f = open('ImageSets/train_messi.txt', 'w')
for annot in train_data:
name = annot[: annot.index('.xml')]
png_image = 'images/' + name + '.png'
if isfile(png_image):
f.write(png_image + "\t" + "annotations/" + annot + "\n")
f.close()
f = open('ImageSets/test_messi.txt', 'w')
for annot in test_data:
name = annot[: annot.index('.xml')]
png_image = 'images/' + name + '.png'
if isfile(png_image):
f.write(png_image + "\t" + "annotations/" + annot + "\n")
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment