-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathAttrListGen.py
More file actions
40 lines (33 loc) · 948 Bytes
/
AttrListGen.py
File metadata and controls
40 lines (33 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import numpy as np
import os
import linecache as lc
filelist ='/home/SSD1/celebA/detlist'
dicclebA = '/home/SSD1/celebA/list_attr_celeba.txt'
arr = []
with open(dicclebA) as lmfile:
lineNum=sum(1 for _ in lmfile)
it=iter(range(1, lineNum))
for m in it:
line = lc.getline(dicclebA, m)
Name = line.rstrip('\n')
file = Name.split(" ")
ImgName = '/home/SSD1/celebA/det/' + file[0]
attr = Name[11:]
arr.append(ImgName)
arr.append(attr)
with open(filelist) as lmfile:
lineNum=sum(1 for _ in lmfile)
it=iter(range(1, lineNum))
for m in it:
line = lc.getline(filelist, m)
line = line.rstrip('\n')
file = line.split('/')
ImgName = '/home/SSD1/celebA/det/' + file[2]
try:
idx = arr.index(ImgName)
attr = arr[idx+1]
newline = ImgName + " " + attr
with open('detcelebAG',"a+") as outfile:
outfile.write(newline + "\n")
except:
print(ImgName)