Skip to content

Instantly share code, notes, and snippets.

@kalaspuffar
Created June 5, 2018 12:37
Show Gist options
  • Save kalaspuffar/2eabd4d38cd3a7de0dde4b35c8be7aa3 to your computer and use it in GitHub Desktop.
Save kalaspuffar/2eabd4d38cd3a7de0dde4b35c8be7aa3 to your computer and use it in GitHub Desktop.
import re
addrs = [
'PetImages/A/test1.jpg',
'PetImages/B/test3.jpg',
'PetImages/B/test3.jpg',
'PetImages/C/test4.jpg',
'PetImages/D/test2.jpg',
'PetImages/C/test4.jpg',
'PetImages/A/test1.jpg',
'PetImages/D/test2.jpg'
]
letterString = 'ABCDEFGHJKLMNOPQRSTUVWXYZ'
labels = []
for addr in addrs:
m = re.match('PetImages/([A-Z])/.*', addr)
labels.append(letterString.find(m.group(1)))
print labels
@deeptibhegde
Copy link

Hi @kalaspuffar. I am trying out this code for around 40 classes, however my label names are not single letters such A,B,C. They have such names as character_1_ka. As i understand, the letterString looks at each character of the string as a label, yes? Would this be fixed by creating an array of strings as letterString?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment