Skip to content

Instantly share code, notes, and snippets.

@sydney0zq
Last active September 30, 2017 01:31
Show Gist options
  • Save sydney0zq/2cc865034daf0f3d9e3fcdfd458eac81 to your computer and use it in GitHub Desktop.
Save sydney0zq/2cc865034daf0f3d9e3fcdfd458eac81 to your computer and use it in GitHub Desktop.
Auto label face -- MacOS
import os
if os.path.isfile("label.txt"):
f = open("label.txt", "a+")
else:
f = open("label.txt", "w")
if os.path.isdir("unsure"):
print (" | Create unsure directory please...")
if os.path.isdir("asia"):
print (" | Create asia directory please...")
if os.path.isdir("notasia"):
print (" | Create notasia directory please...")
num = len(os.listdir("."))
i = 0
for imname in os.listdir("."):
#print (imname)
try:
s = ""
if imname[-3:] == "jpg":
print (imname)
os.system("open " + imname)
b = input()
if b == "":
b = "0"
if int(b) == 1:
s = imname[:-4] + " " + b + "\n"
s += imname[:-4] + " " + str(1-int(b)) + "\n"
os.rename("./"+imname, "./asia/"+imname)
i += 1
elif int(b) == 0:
s = imname[:-4] + " " + b + "\n"
s += imname[:-4] + " " + str(1-int(b)) + "\n"
os.rename("./"+imname, "./notasia/"+imname)
i += 1
elif int(b) == 2:
os.rename("./"+imname, "./unsure/"+imname)
else:
print (" | ERROR!")
raise KeyboardInterrupt
f.write(s)
print ("process ", i, "/", num)
except KeyboardInterrupt:
f.close()
exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment