Skip to content

Commit

Permalink
Initial crowdai commit
Browse files Browse the repository at this point in the history
  • Loading branch information
amir-abdi committed Jul 16, 2019
1 parent ac36c72 commit 78e9545
Show file tree
Hide file tree
Showing 21 changed files with 1,045 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
scratch
saved_models
wandb
checkpoints
Expand Down
8 changes: 8 additions & 0 deletions aicrowd.json
@@ -0,0 +1,8 @@
{
"challenge_id": "aicrowd-neurips-2019-disentanglement-challenge",
"grader_id": "aicrowd-neurips-2019-disentanglement-challenge",
"authors": ["amirabdi"],
"description": "Pytorch implementation of disentanglement algorithms",
"license": "MIT",
"gpu": true
}
66 changes: 66 additions & 0 deletions aicrowd_helpers.py
@@ -0,0 +1,66 @@
#!/usr/bin/env python
import crowdai_api
import os

########################################################################
# Instatiate Event Notifier
########################################################################
crowdai_events = crowdai_api.events.CrowdAIEvents()


def execution_start():
########################################################################
# Register Evaluation Start event
########################################################################
print("Training Start...")
crowdai_events.register_event(
event_type=crowdai_events.CROWDAI_EVENT_INFO,
message="execution_started",
payload={ #Arbitrary Payload
"event_type": "disentanglement_challenge:execution_started"
}
)


def register_progress(progress):
########################################################################
# Register Evaluation Progress event
# progress : float [0, 1]
########################################################################
print("Training Progress : {}".format(progress))
crowdai_events.register_event(
event_type=crowdai_events.CROWDAI_EVENT_INFO,
message="register_progress",
payload={ #Arbitrary Payload
"event_type": "disentanglement_challenge:register_progress",
"training_progress" : progress
}
)

def submit(payload={}):
########################################################################
# Register Evaluation Complete event
########################################################################
print("AIcrowd Submit")
crowdai_events.register_event(
event_type=crowdai_events.CROWDAI_EVENT_SUCCESS,
message="submit",
payload={ #Arbitrary Payload
"event_type": "disentanglement_challenge:submit",
},
blocking=True
)

def execution_error(error):
########################################################################
# Register Evaluation Complete event
########################################################################
crowdai_events.register_event(
event_type=crowdai_events.CROWDAI_EVENT_ERROR,
message="execution_error",
payload={ #Arbitrary Payload
"event_type": "disentanglement_challenge:execution_error",
"error" : error
},
blocking=True
)
5 changes: 5 additions & 0 deletions apt.txt
@@ -0,0 +1,5 @@
curl
gcc
git
vim
ssh
19 changes: 4 additions & 15 deletions common/dataset.py
Expand Up @@ -57,6 +57,7 @@ def __init__(self, root, transform, labels, label_weights, name, class_values, n

self.label_handler = LabelHandler(labels, label_weights, class_values)

@property
def name(self):
return self._name

Expand All @@ -76,22 +77,15 @@ def num_channels(self):
return self._num_channels

def __getitem__(self, index1):
index2 = random.choice(self.indices)

path1 = self.imgs[index1][0]
path2 = self.imgs[index2][0]
img1 = self.loader(path1)
img2 = self.loader(path2)
if self.transform is not None:
img1 = self.transform(img1)
img2 = self.transform(img2)

label1 = 0
label2 = 0
if self.label_handler.has_labels():
label1 = self.label_handler.get_label(index1)
label2 = self.label_handler.get_label(index2)
return img1, img2, label1, label2
return img1, label1


class CustomNpzDataset(Dataset):
Expand All @@ -106,6 +100,7 @@ def __init__(self, data_images, transform, labels, label_weights, name, class_va
self.transform = transform
self.indices = range(len(self))

@property
def name(self):
return self._name

Expand All @@ -125,20 +120,14 @@ def num_channels(self):
return self._num_channels

def __getitem__(self, index1):
index2 = random.choice(self.indices)

img1 = Image.fromarray(self.data_npz[index1] * 255)
img2 = Image.fromarray(self.data_npz[index2] * 255)
if self.transform is not None:
img1 = self.transform(img1)
img2 = self.transform(img2)

label1 = 0
label2 = 0
if self.label_handler.has_labels():
label1 = self.label_handler.get_label(index1)
label2 = self.label_handler.get_label(index2)
return img1, img2, label1, label2
return img1, label1

def __len__(self):
return self.data_npz.shape[0]
Expand Down
4 changes: 2 additions & 2 deletions common/utils.py
Expand Up @@ -123,7 +123,7 @@ def random_idx():
return random.randint(0, dataset.__len__() - 1)

sample_idx = {}
dset_name = dataset.name()
dset_name = dataset.name
if dset_name.lower() == 'dsprites':
fixed_idx = [87040, 332800, 578560] # square ellipse heart
sample_idx = {'{}_{}'.format(c.FIXED, c.SQUARE): fixed_idx[0],
Expand Down Expand Up @@ -156,7 +156,7 @@ def random_idx():

labels[key] = None
if dataset.has_labels():
labels[key] = data[2].to(device, dtype=torch.long).unsqueeze(0)
labels[key] = data[1].to(device, dtype=torch.long).unsqueeze(0)

return images, labels

Expand Down

0 comments on commit 78e9545

Please sign in to comment.