Skip to content

Commit

Permalink
update the various comet scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
TrentWeiss committed Jan 4, 2021
1 parent 4f1599d commit 4272069
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 56 deletions.
59 changes: 25 additions & 34 deletions DCNN-Pytorch/get_comet_experiment_ame2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
parser.add_argument("--epoch_number", type=int, required=False, default=100, help="Experiment key to grab from comet.")
parser.add_argument("--output_directory", type=str, required=False, default=".", help="Where to put the config and data files.")

projectdict = {"cnnlstm" : "deepracingcnnlstm", "bezier" : "deepracingbezierpredictor", "pilot" : "deepracingpilotnet"}
#XMUs9uI19KQNdYrQhuXPnAfpB
args = parser.parse_args()
args = parser.parse_args()
experiment_key = args.experiment_key
epoch_number = args.epoch_number
restkey = args.restkey
Expand All @@ -29,60 +30,50 @@
api = API()
else:
api = API(rest_api_key=restkey)

experiment : APIExperiment = api.get_experiment("electric-turtle", "deepracingadmiralnet-e2e", experiment_key)
experiment : APIExperiment = api.get_experiment("electric-turtle", "deepracingposepredictor", experiment_key)
assetlist = experiment.get_asset_list()
assetdict = {d['fileName']: d['assetId'] for d in assetlist}


print("Getting hyperparameters from comet")
parameters_summary = experiment.get_parameters_summary()
configin = {d["name"] : d["valueCurrent"] for d in parameters_summary}
config = {}
config["image_size"] = np.fromstring( configin["image_size"].replace(" ","").replace("[","").replace("]",""), sep=',', dtype=np.int32 ).tolist()
# try:
# config["image_size"] = np.fromstring( configin["image_size"].replace(" ","").replace("[","").replace("]",""), sep=',', dtype=np.int32 ).tolist()
# except:
# config["image_size"] = [66,200]
config["input_channels"] = int( configin["input_channels"] )
config["hidden_dimension"] = int( configin["hidden_dimension"] )
config["sequence_length"] = int( configin["sequence_length"] )
config["context_length"] = int( configin["context_length"] )
config["output_dimension"] = int( configin["output_dimension"] )

print(config)
outputconfigfile = os.path.join(output_directory,"config.yaml")
with open(outputconfigfile, 'w') as f:
yaml.dump(config,stream=f,Dumper=yaml.SafeDumper)


#get network weight file
weightfilename = "admiralnet_epoch_%d_params.pt" %(epoch_number,)
optimizerfilename = "admiralnet_epoch_%d_optimizer.pt" %(epoch_number,)
weightfilename = "epoch_%d_params.pt" %(epoch_number,)
optimizerfilename = "epoch_%d_optimizer.pt" %(epoch_number,)

print("Getting network weights from comet")
params_binary = experiment.get_asset(assetdict[weightfilename])

outputweightfile = os.path.join(output_directory,weightfilename)
with open(outputweightfile, 'wb') as f:
f.write(params_binary)

#get optimizer weight file
print("Getting optimizer weights from comet")
optimizer_binary = experiment.get_asset(assetdict[optimizerfilename])

outputweightfile = os.path.join(output_directory,weightfilename)
with open(outputweightfile, 'wb') as f:
f.write(params_binary)

outputoptimizerfile = os.path.join(output_directory,optimizerfilename)
with open(outputoptimizerfile, 'wb') as f:
f.write(optimizer_binary)

#get parameters
parameters_summary = experiment.get_parameters_summary()
configin = {d["name"] : d["valueCurrent"] for d in parameters_summary}
config = {}
config["image_size"] = np.fromstring(configin["image_size"].replace(" ","")[1:-1],sep=',').astype(np.int32).tolist()
config["input_channels"] = int( configin["input_channels"] )
config["hidden_dimension"] = int( configin["hidden_dimension"] )
config["sequence_length"] = int( configin["sequence_length"] )
config["context_length"] = int( configin["context_length"] )
print(config)


outputconfigfile = os.path.join(output_directory,"config.yaml")
with open(outputconfigfile, 'w') as f:
yaml.dump(config,stream=f,Dumper=yaml.SafeDumper)

context_length = config["context_length"]
sequence_length = config["sequence_length"]
input_channels = config["input_channels"]
hidden_dimension = config["hidden_dimension"]
output_dimension = config["output_dimension"]
net = deepracing_models.nn_models.Models.AdmiralNetKinematicPredictor( context_length = context_length , sequence_length = sequence_length, input_channels=input_channels, hidden_dim = hidden_dimension, output_dimension=output_dimension)
sequence_length = config["sequence_length"]
net = deepracing_models.nn_models.Models.AdmiralNetKinematicPredictor( sequence_length = sequence_length, context_length = context_length , input_channels=input_channels, hidden_dim = hidden_dimension )
net = net.double()
with open(outputweightfile, 'rb') as f:
net.load_state_dict(torch.load(f, map_location=torch.device("cpu")))
19 changes: 10 additions & 9 deletions DCNN-Pytorch/get_comet_experiment_cnnlstm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import torch.nn as NN
import numpy as np
import torch.utils.data as data_utils
import deepracing_models.data_loading.proto_datasets as PD
from tqdm import tqdm as tqdm
import deepracing_models.nn_models.LossFunctions as loss_functions
import deepracing_models.nn_models.Models
parser = argparse.ArgumentParser(description="Download experiment from Comet.ml")
parser.add_argument("experiment_key", type=str, help="Experiment key to grab from comet.")
Expand All @@ -22,7 +20,7 @@
experiment_key = args.experiment_key
epoch_number = args.epoch_number
restkey = args.restkey
output_directory = os.path.join(args.output_directory, experiment_key + "_from_comet")
output_directory = os.path.join(args.output_directory, experiment_key)
if not os.path.isdir(output_directory):
os.makedirs(output_directory)
if restkey is None:
Expand All @@ -34,16 +32,19 @@
assetdict = {d['fileName']: d['assetId'] for d in assetlist}
#print(assetdict)
#get network weight file
weightfilename = "pilotnet_epoch_%d_params.pt" %(epoch_number,)
weightfilenamealt = "CNNLSTM_epoch_%d_params.pt" %(epoch_number,)
weightfilename = "CNNLSTM_epoch_%d_params.pt" %(epoch_number,)
weightfilenamealt = "epoch_%d_params.pt" %(epoch_number,)
weightfilenamealtalt = "pilotnet_epoch_%d_params.pt" %(epoch_number,)

print("Getting network weights from comet")
try:
params_binary = experiment.get_asset(assetdict[weightfilename])
outputweightfile = os.path.join(output_directory,weightfilename)
except KeyError as e:
params_binary = experiment.get_asset(assetdict[weightfilenamealt])
outputweightfile = os.path.join(output_directory,weightfilenamealt)
try:
params_binary = experiment.get_asset(assetdict[weightfilename])
except KeyError as e:
params_binary = experiment.get_asset(assetdict[weightfilenamealtalt])
outputweightfile = os.path.join(output_directory,"epoch_%d_params.pt" %(epoch_number,))



Expand All @@ -56,7 +57,7 @@
config = {}
config["image_size"] = np.fromstring( configin["image_size"].replace(" ","")[1:-1], sep=',', dtype=np.int32).tolist()
config["input_channels"] = int( configin["input_channels"] )
config["output_dimension"] = int( configin["output_dimension"] )
config["output_dimension"] = int( configin.get("output_dimension","2") )
config["hidden_dimension"] = int( configin.get("hidden_dimension","100") )
config["sequence_length"] = int( configin["sequence_length"] )
config["context_length"] = int( configin.get("context_length","5") )
Expand Down
24 changes: 11 additions & 13 deletions DCNN-Pytorch/get_comet_experiment_waypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
import torch.nn as NN
import numpy as np
import torch.utils.data as data_utils
import deepracing_models.data_loading.proto_datasets as PD
from tqdm import tqdm as tqdm
import deepracing_models.nn_models.LossFunctions as loss_functions
import deepracing_models.nn_models.Models
parser = argparse.ArgumentParser(description="Download experiment from Comet.ml")
parser.add_argument("experiment_key", type=str, help="Experiment key to grab from comet.")
parser.add_argument("--restkey", type=str, required=False, default=None, help="Experiment key to grab from comet.")
parser.add_argument("--epoch_number", type=int, required=False, default=100, help="Experiment key to grab from comet.")
parser.add_argument("--output_directory", type=str, required=False, default=".", help="Where to put the config and data files.")
parser.add_argument("--get_optimizer_weights", action="store_true", help="Also grab the state dictionary of the optimizer at the end of the specified epoch")

projectdict = {"cnnlstm" : "deepracingcnnlstm", "bezier" : "deepracingbezierpredictor", "pilot" : "deepracingpilotnet"}
#XMUs9uI19KQNdYrQhuXPnAfpB
args = parser.parse_args()
experiment_key = args.experiment_key
epoch_number = args.epoch_number
restkey = args.restkey
output_directory = os.path.join(args.output_directory, experiment_key + "_from_comet")
get_optimizer_weights = args.get_optimizer_weights
output_directory = os.path.join(args.output_directory, experiment_key)
if not os.path.isdir(output_directory):
os.makedirs(output_directory)
if restkey is None:
Expand All @@ -36,22 +36,20 @@

#get network weight file
weightfilename = "epoch_%d_params.pt" %(epoch_number,)
optimizerfilename = "epoch_%d_optimizer.pt" %(epoch_number,)

print("Getting network weights from comet")
params_binary = experiment.get_asset(assetdict[weightfilename])

#get optimizer weight file
print("Getting optimizer weights from comet")
optimizer_binary = experiment.get_asset(assetdict[optimizerfilename])

outputweightfile = os.path.join(output_directory,weightfilename)
with open(outputweightfile, 'wb') as f:
f.write(params_binary)

outputoptimizerfile = os.path.join(output_directory,optimizerfilename)
with open(outputoptimizerfile, 'wb') as f:
f.write(optimizer_binary)
if get_optimizer_weights:
#get optimizer weight file
print("Getting optimizer weights from comet")
optimizerfilename = "epoch_%d_optimizer.pt" %(epoch_number,)
optimizer_binary = experiment.get_asset(assetdict[optimizerfilename])
outputoptimizerfile = os.path.join(output_directory,optimizerfilename)
with open(outputoptimizerfile, 'wb') as f:
f.write(optimizer_binary)

#get parameters
parameters_summary = experiment.get_parameters_summary()
Expand Down

0 comments on commit 4272069

Please sign in to comment.