-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Util to convert labelbox CSV to our labels.csv format
- Loading branch information
1 parent
01a12b1
commit ecfb8f5
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import csv | ||
import random | ||
import json | ||
|
||
with open("newlabels.csv", "w", newline="") as csvfile: | ||
# Open the old labels file | ||
with open("labelbox.csv", newline="") as oldfile: | ||
# Get the header labels | ||
csvreader = csv.DictReader(oldfile) | ||
fieldnames = next(csvreader) | ||
labelwriter = csv.DictWriter(csvfile, fieldnames=["filename", "login", "custom404", "homepage", "oldlooking", "evaluation"]) | ||
labelwriter.writeheader() | ||
|
||
# Loop through the file | ||
rows = [] | ||
for row in csvreader: | ||
filename = row["External ID"] | ||
print(row["Label"]) | ||
labelstring = row["Label"] | ||
if row["Label"] == "Skip": | ||
labelstring = '{"imageclassification":[]}' | ||
labels = json.loads(labelstring) | ||
|
||
newrow = dict() | ||
newrow["filename"] = filename | ||
newrow["oldlooking"] = True | ||
newrow["login"] = "loginpage" in labels["imageclassification"] | ||
newrow["homepage"] = "homepage" in labels["imageclassification"] | ||
newrow["custom404"] = "custom404"in labels["imageclassification"] | ||
|
||
newrow["evaluation"] = random.random() > 0.8 | ||
|
||
rows.append(newrow) | ||
labelwriter.writerows(rows) | ||
print("Made new labels file: newlabels.csv") |