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

CoSTAR Dataset Joints vector embeddings #21

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
c7bd6b6
genotypes.py random path
ahundt Mar 22, 2019
5c5c866
train.py add flops_shape
ahundt Mar 22, 2019
65a2a20
added new feature-mode:time_difference_images to classify time interv…
priyankahubli Apr 6, 2019
a965ce0
cnn/genotypes.py first try at sharper search space
ahundt Apr 9, 2019
d9a54bf
cnn/visualize.py beter style params
ahundt Apr 9, 2019
284f92d
WARNING UNCLEAR CODE STATE cnn/model_search.py merge graph search alg…
ahundt Apr 9, 2019
1354bea
WARNING UNCLEAR CODE STATE genotypes.py fixes to multichannel hyperpa…
ahundt Apr 9, 2019
a79c3da
Merge branch 'multi_channel_search' into multi_channel_search_merge
ahundt Apr 9, 2019
6f0190e
cnn/genotypes.py comments fix
ahundt Apr 9, 2019
8857278
Merge branch 'multi_channel_search_merge' into sharper for consistenc…
ahundt Apr 9, 2019
0c41d94
cnn/genotypes.py sharper add missing ops
ahundt Apr 9, 2019
6b5c161
cnn/operations.py sharper flood_conv_3x3 added
ahundt Apr 9, 2019
9342d1e
cnn/genotypes.py SHARPER_PRIMITIVES disable dil_flood_conv_5x5 due to…
ahundt Apr 9, 2019
efa1168
cnn/model_search.py fix debugging code for MixedOp() class
ahundt Apr 9, 2019
17fbc78
modified TDCFeaturizer forward function to be able to choose differen…
priyankahubli Apr 20, 2019
7e16362
cnn/genotypes.py add first "sharper" search space models
ahundt Apr 20, 2019
ddc4ff3
cnn/genotypes.py sharper flops
ahundt Apr 20, 2019
8166e1c
cnn/genotypes.py add cifar10 startup command to sharper models
ahundt Apr 20, 2019
c4891da
cnn/genotype_extractor.py added, can disable 'none' layer hack from D…
ahundt May 12, 2019
d7791b5
cnn/visualize.py different genotypes get different filenames
ahundt May 12, 2019
f0f88d6
README.md first sharpDARTS readme
ahundt May 15, 2019
b374f37
train.py add SHARPER_PRIMITIVES option to help
ahundt May 15, 2019
fc79091
genotypes.py update sharper no hacks run command
ahundt May 15, 2019
72601bd
README.md ack-grep command
ahundt May 15, 2019
ee54e59
README.md add differentiable hyperparameter search
ahundt May 15, 2019
6904ca2
README.md explain cosine power annealing
ahundt May 15, 2019
9cd0551
cnn/visualize.py improve viz to make sense
ahundt May 30, 2019
a7bce07
Merge branch 'sharper' of github.com:ahundt/sharpDARTS into sharper
ahundt May 30, 2019
690f581
LICENSE copyright update
ahundt May 30, 2019
4415de8
dataset.py reference source for some lines in this file
ahundt May 30, 2019
45a1bd2
cnn/visualize.py improve viz to make sense
ahundt May 30, 2019
a4e9ac0
README.md updated with new details
ahundt May 30, 2019
dc40580
README.md add images
ahundt May 30, 2019
422e3e4
README.md typo fixes
ahundt May 30, 2019
8e4d5f8
README.md add svg images of cos power annealing
ahundt May 31, 2019
0eb5d90
README.md caps fix
ahundt Jun 4, 2019
a6dc731
README.md clarify steps for model search.
ahundt Jun 4, 2019
91532e6
README.md typo fix
ahundt Jun 4, 2019
f658023
README.md explain how to generate cosine power annealing charts.
ahundt Jun 4, 2019
c7fbb0f
Merge branch 'sharper_docs' into sharper
ahundt Jun 5, 2019
d0c86e4
Added support for Cross-Modal embedding
priyankahubli Jun 8, 2019
a00cf24
added visualization and testing reader code
priyankahubli Jun 24, 2019
6dd3a9c
resolved merged conflicts by incorporating both suggestions
priyankahubli Jun 24, 2019
7be01d3
moved test reader to costar_dataset
priyankahubli Jun 25, 2019
b20fa1a
added default dataset path in visualize_embeddings.py
priyankahubli Jul 10, 2019
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
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2018, Hanxiao Liu.
Copyright (c) 2019 Andrew Hundt, Varun Jain, and the Code Authors. Copyright (c) 2018, Hanxiao Liu.
All rights reserved.

Apache License
Expand Down
293 changes: 277 additions & 16 deletions README.md

Large diffs are not rendered by default.

13 changes: 10 additions & 3 deletions cnn/dataset.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Code to load various datasets for training.
#
# Some data loading code is from https://github.com/DRealArun/darts/ with the same license as DARTS.
import os
import sys
import time
Expand All @@ -13,7 +16,7 @@
import torchvision.datasets as dset
import torch.backends.cudnn as cudnn
try:
import costar_dataset
import costar_dataset
except ImportError:
print('dataset.py: The costar dataset is not available, so it is being skipped. '
'See https://github.com/ahundt/costar_dataset for details')
Expand Down Expand Up @@ -83,13 +86,17 @@

costar_class_dict = {'translation_only': 3,
'rotation_only': 5,
'all_features': 8}
'all_features': 8,
'time_difference_images': 6,
'cross_modal_embeddings': 6}
costar_supercube_inp_channel_dict = {'translation_only': 52,
'rotation_only': 55,
'all_features': 57}
costar_vec_size_dict = {'translation_only': 44,
'rotation_only': 49,
'all_features': 49}
'all_features': 49,
'time_difference_images': 0,
'cross_modal_embeddings': 20}

COSTAR_SET_NAMES = ['blocks_only', 'blocks_with_plush_toy']
COSTAR_SUBSET_NAMES = ['success_only', 'error_failure_only', 'task_failure_only', 'task_and_error_failure']
Expand Down
137 changes: 137 additions & 0 deletions cnn/genotype_extractor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
'''
This file includes code from the DARTS and sharpDARTS https://arxiv.org/abs/1903.09900 papers.
'''

import numpy as np
import genotypes


def parse_cell(weights, primitives, steps=4, skip_primitive='none'):
""" Take a weight array and turn it into a list of pairs (primitive_string, node_index).
"""
gene = []
n = 2
start = 0
for add_node_index in range(steps):
# Each step is a separate "add node" in the graph, so i is the integer index of the current node.
# A better name for i might be add_node_index.
end = start + n
# Only look at the weights relevant to this node.
# "Nodes" 0 and 1 will always be the output of the previous cells.
#
# All other nodes will be add nodes which need edges connecting back to the previous nodes:
# add node 0 will need 2: rows 0, 1
# add node 1 will need 3: rows 2, 3, 4
# add node 2 will need 4: rows 5, 6, 7, 8
# add node 3 will need 5: rows 9, 10, 11, 12, 13
# ...and so on if there are more than 4 nodes.
W = weights[start:end].copy()
# print('add_node_index: ' + str(add_node_index) + ' start: ' + str(start) + ' end: ' + str(end) + ' W shape: ' + str(W.shape))
# Each row in the weights is a separate edge, and each column are the possible primitives that edge might use.
# The first "add node" can connect back to the two previous cells, which is why the edges are i + 2.
# The sorted function orders lists from lowest to highest, so we use -max in the lambda function to sort from highest to lowest.
# We currently say there will only be two edges connecting to each node, which is why there is [:2], to select the two highest score edges.
# Each later nodes can connect back to the previous cells or an internal node, so the range(i+2) of possible connections increases.
pre_edges = sorted(range(add_node_index + 2),
key=lambda x: -max(W[x][k] for k in range(len(W[x])) if skip_primitive is None or k != primitives.index(skip_primitive)))
edges = pre_edges[:2]
# print('edges: ' + str(edges))
# We've now selected the two edges we will use for this node, so next let's select the layer primitives.
# Each edge needs a particular primitive, so go through all the edges and compare all the possible primitives.
for j in edges:
k_best = None
# note: This probably could be simpler via argmax...
# Loop through all the columns to find the highest score primitive for the chosen edge, excluding none.
for k in range(len(W[j])):
if skip_primitive is None or k != primitives.index(skip_primitive):
if k_best is None or W[j][k] > W[j][k_best]:
k_best = k
# Once the best primitive is chosen, create the new gene element, which is the
# string for the name of the primitive, and the index of the previous node to connect to,
gene.append((primitives[k_best], j))
start = end
n += 1
# Return the full list of (node, primitive) pairs for this set of weights.
return gene

def genotype_cell(alphas_normal, alphas_reduce, primitives, steps=4, multiplier=4, skip_primitive='none'):
# skip_primitive = 'none' is a hack in original DARTS, which removes a no-op primitive.
# skip_primitive = None means no hack is applied
# note the printed weights from a call to Network::arch_weights() in model_search.py
# are already post-softmax, so we don't need to apply softmax again
# alphas_normal = torch.FloatTensor(genotypes.SHARPER_SCALAR_WEIGHTS.normal)
# alphas_reduce = torch.FloatTensor(genotypes.SHARPER_SCALAR_WEIGHTS.reduce)
# F.softmax(alphas_normal, dim=-1).data.cpu().numpy()
# F.softmax(alphas_reduce, dim=-1).data.cpu().numpy()
gene_normal = parse_cell(alphas_normal, primitives, steps, skip_primitive=skip_primitive)
gene_reduce = parse_cell(alphas_reduce, primitives, steps, skip_primitive=skip_primitive)

concat = range(2+steps-multiplier, steps+2)
genotype = genotypes.Genotype(
normal=gene_normal, normal_concat=concat,
reduce=gene_reduce, reduce_concat=concat,
layout='cell',
)
return genotype


def main():
'''
Parse raw weights with the hack that excludes the 'none' primitive, and without that hack.
Then print out the final genotypes.
'''
# Set these variables to the ones you're using in this case from genotypes.py
skip_primitive = None
raw_weights_genotype = genotypes.SHARPER_SCALAR_WEIGHTS
primitives = genotypes.SHARPER_PRIMITIVES
# get the normal and reduce weights as a numpy array
alphas_normal = np.array(raw_weights_genotype.normal)
alphas_reduce = np.array(raw_weights_genotype.reduce)

# for steps, see layers_in_cells in train_search.py
steps = 4
# for multiplier, see multiplier for Network class in model_search.py
multiplier = 4
# note the printed weights from a call to Network::arch_weights() in model_search.py
# are already post-softmax, so we don't need to apply softmax again
# alphas_normal = torch.FloatTensor(genotypes.SHARPER_SCALAR_WEIGHTS.normal)
# alphas_reduce = torch.FloatTensor(genotypes.SHARPER_SCALAR_WEIGHTS.reduce)
# F.softmax(alphas_normal, dim=-1).data.cpu().numpy()
# F.softmax(alphas_reduce, dim=-1).data.cpu().numpy()

# skip_primitive = 'none' is a hack in original DARTS, which removes a no-op primitive.
# skip_primitive = None means no hack is applied
print('#################')
genotype = genotype_cell(alphas_normal, alphas_reduce, primitives, steps=4, multiplier=4, skip_primitive='none')
print('SHARPER_SCALAR_genotype_skip_none = ' + str(genotype))
genotype = genotype_cell(alphas_normal, alphas_reduce, primitives, steps=4, multiplier=4, skip_primitive=None)
print('SHARPER_SCALAR_genotype_no_hack = ' + str(genotype))
# Set these variables to the ones you're using in this case from genotypes.py
skip_primitive = None
raw_weights_genotype = genotypes.SHARPER_MAX_W_WEIGHTS
primitives = genotypes.SHARPER_PRIMITIVES
# get the normal and reduce weights as a numpy array
alphas_normal = np.array(raw_weights_genotype.normal)
alphas_reduce = np.array(raw_weights_genotype.reduce)

# for steps, see layers_in_cells in train_search.py
steps = 4
# for multiplier, see multiplier for Network class in model_search.py
multiplier = 4
# note the printed weights from a call to Network::arch_weights() in model_search.py
# are already post-softmax, so we don't need to apply softmax again
# alphas_normal = torch.FloatTensor(genotypes.SHARPER_SCALAR_WEIGHTS.normal)
# alphas_reduce = torch.FloatTensor(genotypes.SHARPER_SCALAR_WEIGHTS.reduce)
# F.softmax(alphas_normal, dim=-1).data.cpu().numpy()
# F.softmax(alphas_reduce, dim=-1).data.cpu().numpy()

# skip_primitive = 'none' is a hack in original DARTS, which removes a no-op primitive.
# skip_primitive = None means no hack is applied
print('#################')
genotype = genotype_cell(alphas_normal, alphas_reduce, primitives, steps=4, multiplier=4, skip_primitive='none')
print('SHARPER_MAX_W_genotype_skip_none = ' + str(genotype))
genotype = genotype_cell(alphas_normal, alphas_reduce, primitives, steps=4, multiplier=4, skip_primitive=None)
print('SHARPER_MAX_W_genotype_no_hack = ' + str(genotype))

if __name__ == '__main__':
main()
Loading