Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add progress bar #15

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions cocosplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from sklearn.model_selection import train_test_split
from skmultilearn.model_selection import iterative_train_test_split
import numpy as np
from tqdm import tqdm

np.random.seed(42)

def save_coco(file, info, licenses, images, annotations, categories):
with open(file, 'wt', encoding='UTF-8') as coco:
Expand All @@ -13,14 +15,14 @@ def save_coco(file, info, licenses, images, annotations, categories):

def filter_annotations(annotations, images):
image_ids = funcy.lmap(lambda i: int(i['id']), images)
return funcy.lfilter(lambda a: int(a['image_id']) in image_ids, annotations)

filtered_annotations = funcy.lfilter(lambda a: int(a['image_id']) in image_ids, tqdm(annotations, desc='Filtering Annotations'))
return filtered_annotations

def filter_images(images, annotations):

annotation_ids = funcy.lmap(lambda i: int(i['image_id']), annotations)
filtered_images = funcy.lfilter(lambda a: int(a['id']) in annotation_ids, tqdm(images, desc='Filtering Images'))
return filtered_images

return funcy.lfilter(lambda a: int(a['id']) in annotation_ids, images)


parser = argparse.ArgumentParser(description='Splits COCO annotations file into training and test sets.')
Expand Down Expand Up @@ -67,7 +69,7 @@ def main(args):
annotations = funcy.lremove(lambda i: i['category_id'] not in annotation_categories , annotations)


X_train, y_train, X_test, y_test = iterative_train_test_split(np.array([annotations]).T,np.array([ annotation_categories]).T, test_size = 1-args.split)
X_train, y_train, X_test, y_test = iterative_train_test_split(np.array([annotations]).T,np.array([ annotation_categories]).T, test_size = 1-args.split, random_state=42)

save_coco(args.train, info, licenses, filter_images(images, X_train.reshape(-1)), X_train.reshape(-1).tolist(), categories)
save_coco(args.test, info, licenses, filter_images(images, X_test.reshape(-1)), X_test.reshape(-1).tolist(), categories)
Expand All @@ -76,7 +78,7 @@ def main(args):

else:

X_train, X_test = train_test_split(images, train_size=args.split)
X_train, X_test = train_test_split(images, train_size=args.split, random_state=42)

anns_train = filter_annotations(annotations, X_train)
anns_test=filter_annotations(annotations, X_test)
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ sklearn
funcy
argparse
scikit-multilearn
tqdm