def main(): project_name = 'PolyominoWorld' for param_path, label in gen_param_paths( project_name, param2requests, param2default, runs_path=None, ludwig_data_path=None, ): with (param_path / 'param2val.yaml').open('r') as f: param2val = yaml.load(f, Loader=yaml.FullLoader) params = Params.from_param2val(param2val) for rep_id, path_to_net in enumerate(param_path.rglob('model.pt')): pytorch_model = Network(params) pytorch_model.load_state_dict( torch.load(path_to_net, map_location=torch.device('cpu'))) pytorch_model.eval() dummy_input = torch.zeros( 1, calc_world_vector_size( params.add_grayscale)) # dummy input of expected shape onnx_path_out = Path( __file__ ).parent.parent / 'onnx_models' / f'{param2val["param_name"]}_{rep_id}.onnx' if not onnx_path_out.parent.exists(): onnx_path_out.parent.mkdir() torch.onnx.export(pytorch_model, dummy_input, onnx_path_out, verbose=True) tf_rep = prepare(onnx.load(onnx_path_out)) tf_path_out = Path( __file__ ).parent.parent / 'tensorflow_models' / f'{param2val["param_name"]}_{rep_id}.pb' if not tf_path_out.parent.exists(): tf_path_out.parent.mkdir() tf_rep.export_graph(str(tf_path_out))
from polyominoworld.world import World from polyominoworld.utils import get_leftout_positions from ludwig.results import gen_param_paths HIDDEN_LAYER_ID = 0 if __name__ == '__main__': configs.Device.gpu = False project_name = 'PolyominoWorld' for param_path, label in gen_param_paths( project_name, param2requests, param2default, # isolated=True, # runs_path=Path(__file__).parent.parent / 'runs', ): # load hyper-parameter settings with (param_path / 'param2val.yaml').open('r') as f: param2val = yaml.load(f, Loader=yaml.FullLoader) params = Params.from_param2val(param2val) # re-generate data the way it was during training world = World(params) dataset = DataSet(world.generate_sequences( leftout_colors=params.leftout_colors, leftout_shapes=params.leftout_shapes, leftout_variants=params.leftout_variants,
from entropic.figs import make_predictions_animation from ludwig.results import gen_param_paths SLOT = 'b' LABEL_PARAMS = [] # any additional params to put into label def to_step(file_name): return int(''.join([i for i in file_name if i.isdigit()])) summary_data = [] for param_path, label in gen_param_paths(configs.Dirs.root.name, param2requests, param2default, label_n=False, label_params=LABEL_PARAMS): # num_jobs job_paths = list(param_path.glob(f'*num*')) num_jobs = len(job_paths) # num_ticks npy_paths = list( param_path.glob(f'*num*/saves/output_probabilities_{SLOT}_*.npy')) if not npy_paths: raise SystemExit('Did not find any .npy files') step_set = set([to_step(p.name) for p in npy_paths]) num_ticks = len(step_set) # num_fragments, num_types
CONFIDENCE: float = 0.95 TITLE = '' # f'{SI_NAME}_{PROBES_NAME}.csv' if SD_TYPE == 'sd_n': Y_LABEL: str = f'S_Dbw Score at Input\n +/- 95%-CI' elif SD_TYPE == 'sd_o': Y_LABEL: str = f'S_Dbw Score at Hidden\n +/- 95%-CI' else: raise AttributeError('Invalid SD_TYPE') # collect summaries summaries = [] project_name = __name__ for p, label in gen_param_paths(project_name, param2requests, param2default, runs_path=RUNS_PATH, ludwig_data_path=LUDWIG_DATA_PATH, label_n=LABEL_N): pattern = f'{SD_TYPE}_{PROBES_NAME}' summary = make_summary( pattern, p, label, CONFIDENCE) # summary contains: x, mean_y, std_y, label, n summaries.append(summary) print(f'--------------------- End section {p.name}') print() # sort data summaries = sorted(summaries, key=lambda s: s[1][-1], reverse=True) if not summaries: raise SystemExit('No data found')
""" Count completed jobs, by counting number of saved pytorch models, assuming each job saves 1 model file. To look for results on the shared drive, we use ludwig. We use params.param2requests to tell ludwig which jobs we would like results for. To tell ludwig where to look for results, create an environment variable "LUDWIG_MNT" that points to the path where ludwig_data is mounted on your machine. """ from ludwig.results import gen_param_paths from polyominoworld.params import param2default, param2requests num_completed = 0 project_name = 'PolyominoWorld' for param_path, label in gen_param_paths(project_name, param2requests, param2default, runs_path=None, ludwig_data_path=None, label_n=True): saved_models = [path for path in param_path.rglob('model.pt')] num_completed += len(saved_models) print(f'Found {num_completed} completed jobs.')
param2requests['flavor'] = ['lstm'] param2requests['lr'] = [1.0] if configs.Dirs.summaries.exists(): shutil.rmtree(configs.Dirs.summaries) for slot, context_size in conditions: labels = iter(LABELS) # collect data summary_data = [] color_id = 0 for param_p, label in sorted(gen_param_paths(configs.Dirs.root.name, param2requests, param2default, label_n=True, label_params=LABEL_PARAMS), key=lambda i: i[1], reverse=REVERSE_ORDER): # load data-frame dfs = [] for df_p in param_p.glob( f'*num*/ba_{slot}_context-size={context_size}.csv'): print('Reading {}'.format(df_p.name)) df = pd.read_csv(df_p, index_col=0) df.index.name = 'step' # remove dips df = df.apply(correct_artifacts, result_type='expand', tolerance=TOLERANCE)
from polyominoworld.params import param2default from ludwig.results import gen_param_paths EVAL_LEFTOUT_VARIANTS = True param2requests = { 'leftout_variants': ['half1'], } if __name__ == '__main__': project_name = 'PolyominoWorld' for param_path, label in gen_param_paths( project_name, param2requests, param2default, ): # load hyper-parameter settings with (param_path / 'param2val.yaml').open('r') as f: param2val = yaml.load(f, Loader=yaml.FullLoader) params = Params.from_param2val(param2val) # are any features leftout? if EVAL_LEFTOUT_VARIANTS: leftout_variants_inverse = { 'half1': 'half2', 'half2': 'half1' }[params.leftout_variants] else:
# 4 cumulative_seconds # figure settings LABELS: Optional[List[str]] = None # custom labels for figure legend FIG_SIZE: Tuple[int, int] = (6, 6) # in inches Y_LIMS: Optional[List[float]] = [0., 1.] CONFIDENCE: float = 0.95 TITLE = '' # for each job, save a summary, used for plotting summaries = [] project_name = 'PolyominoWorld' for p, label in gen_param_paths( project_name, param2requests, param2default, # isolated=True, # runs_path=Path(__file__).parent.parent / 'runs', ludwig_data_path=None, label_n=True): summary = make_summary( PATTERN, p, label, CONFIDENCE) # summary contains: x, mean_y, std_y, label, n summaries.append(summary) print(f'--------------------- End section {p.name}') print() # sort data summaries = sorted(summaries, key=lambda s: rank_label_for_legend_order(s[3])) if not summaries: raise SystemExit('No data found')
REPRESENTATIONS_NAME = 'output_probabilities' # "embeddings' or "output_probabilities" """ Note: To convert images into a gif, in terminal: convert -delay 5 FOLDER_NAME/*.png test.gif """ def to_step(file_name): return int(''.join([i for i in file_name if i.isdigit()])) summary_data = [] for param_path, label in gen_param_paths(configs.Dirs.root.name, param2requests, param2default, label_n=False, label_params=['starvation']): # num_jobs job_paths = list(param_path.glob(f'*num*')) num_jobs = len(job_paths) # num_ticks npy_paths = list( param_path.glob(f'*num*/saves/{REPRESENTATIONS_NAME}_*.npy')) step_set = set([to_step(p.name) for p in npy_paths]) num_ticks = len(step_set) # num_fragments, num_types with (param_path / 'param2val.yaml').open('r') as f: param2val = yaml.load(f, Loader=yaml.FullLoader)
'vocab_name': ['con_fe_sent_2.16.20'], 'article_coverage': [1.0], 'window_type': ['backward'], 'window_size': [7] } param2requests.update(update_dict) if MINIMAL: param2requests.update({k: [v] for k, v in param2debug.items()}) # get paths from which to load co-occurrence data project_name = Path.cwd().name paths_to_ww2cf = [] for param_path, label in gen_param_paths( project_name, param2requests, param2default, research_data_path=config.Dirs.research_data, verbose=False): pkl_paths = list(param_path.glob('**/saves/ww2cf.pkl')) if len(pkl_paths) == 0: raise FileNotFoundError(f'Did not find ww2cf.pkl in {param_path}') else: print(f'Found {pkl_paths[0]}') paths_to_ww2cf.append(pkl_paths[0]) # create database db_name = 'sent_b7.sqlite' conn = sqlite3.connect(db_name) c = conn.cursor() try: c.execute('CREATE TABLE cfs (w1 text, w2 text, cf integer)')