Skip to content

Commit

Permalink
Util to convert labelbox CSV to our labels.csv format
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-bishopfox committed Apr 12, 2019
1 parent 01a12b1 commit ecfb8f5
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions utils/labelbox_to_labels.py
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")

0 comments on commit ecfb8f5

Please sign in to comment.