File size: 1,482 Bytes
7ef74d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
45
46
47
48
49
50
import pandas as pd
import sqlite3
from yfcc100m.convert_metadata import generate_rows_from_db
from datadings.tools import yield_threaded
from tqdm import tqdm
df = pd.read_table(
    "yfcc100m_subset_data.tsv", header=None, names=["line_number", "identifier", "hash"]
)
clip_photoids = df["identifier"].tolist()  # 15 million ids
rows = generate_rows_from_db("yfcc100m_dataset.sql", "yfcc100m_dataset")
gen = yield_threaded(rows)
dfs = []
chunk = []
for i, row in enumerate(tqdm(gen, total=100000000)):
    chunk.append(row)
    if (i + 1) % 10_000_000 == 0:
        df = pd.DataFrame(
            chunk,
            columns=[
                "photoid",
                "uid",
                "unickname",
                "datetaken",
                "dateuploaded",
                "capturedevice",
                "title",
                "description",
                "usertags",
                "machinetags",
                "longitude",
                "latitude",
                "accuracy",
                "pageurl",
                "downloadurl",
                "licensename",
                "licenseurl",
                "serverid",
                "farmid",
                "secret",
                "secretoriginal",
                "ext",
                "marker",
            ],
        )
        df = df[df["photoid"].isin(clip_photoids)].reset_index(drop=True)
        dfs.append(df)
        chunk = []
df = pd.concat(dfs)
df.to_csv("yfcc15m.csv", index=False)