qwopqwop commited on
Commit
cc6eb86
1 Parent(s): c6023f8

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +19 -10
README.md CHANGED
@@ -21,7 +21,7 @@ import pandas as pd
21
  dataset = {}
22
  ids = {}
23
  #danbooru 2021
24
- #download 'rsync --recursive --verbose rsync://176.9.41.242:873/danbooru2021/metadata/ ./'
25
  json_data = []
26
  for i in range(0,12):
27
  print(i)
@@ -37,6 +37,7 @@ for i in json_data:
37
  key = -idx
38
  idx += 1
39
  ids[key] = i['tag_string'].replace(' ',', ').replace('_',' ')
 
40
 
41
  #danbooru 2022
42
  #download https://huggingface.co/datasets/animelover/danbooru2022
@@ -46,14 +47,22 @@ for idx,i in enumerate(os.listdir('./danbooru2022/')):
46
  for j in glob.glob(f'./danbooru2022/{i}/*.txt'):
47
  path.append(j)
48
 
49
- for i,p in enumerate(path):
50
- if i % 1000 == 0:
51
- print(i)
52
- name = p.split('/')[-1].split('.')[0]
53
- with open(p, "r") as f:
54
- ids[int(name)] = f.readline()
55
-
56
- del json_data
 
 
 
 
 
 
 
 
57
  dataset['tags'] = ids
58
  dataset = pd.DataFrame(dataset)
59
 
@@ -63,6 +72,6 @@ for i in range(len(dataset)):
63
  print(i)
64
  tags = dataset.iloc[i]['tags'].split(', ')
65
  dataset.iloc[i] = ', '.join([tag for tag in tags if tag not in bad_tags])
66
-
67
  dataset.to_parquet('tags.parquet')
68
  ```
 
21
  dataset = {}
22
  ids = {}
23
  #danbooru 2021
24
+ #download 'rsync --recursive --verbose rsync://176.9.41.242:873/danbooru2021/metadata/ ./metadata'
25
  json_data = []
26
  for i in range(0,12):
27
  print(i)
 
37
  key = -idx
38
  idx += 1
39
  ids[key] = i['tag_string'].replace(' ',', ').replace('_',' ')
40
+ del json_data
41
 
42
  #danbooru 2022
43
  #download https://huggingface.co/datasets/animelover/danbooru2022
 
47
  for j in glob.glob(f'./danbooru2022/{i}/*.txt'):
48
  path.append(j)
49
 
50
+ def load_data(path):
51
+ name = int(path.split('/')[-1].split('.')[0])
52
+ with open(path, "r") as f:
53
+ data = f.readline()
54
+ return name,data
55
+
56
+ with concurrent.futures.ThreadPoolExecutor(max_workers=16) as executor:
57
+ future_to_path = {executor.submit(load_data, p): p for p in path}
58
+ for idx,future in enumerate(concurrent.futures.as_completed(future_to_path)):
59
+ if idx % 1000 == 0:
60
+ print(idx)
61
+ path = future_to_path[future]
62
+ name,data = future.result()
63
+ ids[name] = data
64
+
65
+ #preprocess
66
  dataset['tags'] = ids
67
  dataset = pd.DataFrame(dataset)
68
 
 
72
  print(i)
73
  tags = dataset.iloc[i]['tags'].split(', ')
74
  dataset.iloc[i] = ', '.join([tag for tag in tags if tag not in bad_tags])
75
+ # save
76
  dataset.to_parquet('tags.parquet')
77
  ```