def view_model(request, model_name): """ This view displays a model and its various dependencies and metadatas """ config = Mantra.get_config() models_list = Artefact.all(settings=settings, artefacts_folder=config['models_folder']) if model_name not in models_list: raise Http404("Model does not exist") # delete trial option - catch and process if request.method == 'POST': form = DeleteTrialGroupForm(request.POST) if form.is_valid(): Trial.remove_group_hash_from_contents(settings=settings, trial_group_hash=form.cleaned_data['trial_group_hash']) form = DeleteTrialGroupForm() sys.path.append(settings.MANTRA_PROJECT_ROOT) readme_content, readme_exists = CodeBase.get_readme('%s/models/%s' % (settings.MANTRA_PROJECT_ROOT, model_name)) context = {**Mantra.find_model_metadata(model_name), 'readme_exists': readme_exists, 'readme_content': readme_content} context['files'] = CodeBase.get_files('%s/models/%s'% (settings.MANTRA_PROJECT_ROOT, model_name)) context['directories'] = CodeBase.get_directories('%s/models/%s'% (settings.MANTRA_PROJECT_ROOT, model_name)) trial_group_members, _ = Trial.get_trial_group_members(settings=settings, model_filter=model_name) context['trial_groups'] = Trial.get_all_trial_group_metadata(settings=settings, trial_group_members=trial_group_members) context['trial_groups'].sort(key=lambda item: item['time'], reverse=True) context['form'] = form return render(request, 'view_model.html', context)
def view_dataset_codebase(request, dataset_name, path): """ This view displays a dataset codebase and its various dependencies and metadatas """ config = Mantra.get_config() data_list = Artefact.all(settings=settings, artefacts_folder=config['data_folder']) if dataset_name not in data_list: raise Http404("Dataset does not exist") # delete trial option - catch and process if request.method == 'POST': form = DeleteTrialGroupForm(request.POST) if form.is_valid(): Trial.remove_group_hash_from_contents( settings=settings, trial_group_hash=form.cleaned_data['trial_group_hash']) form = DeleteTrialGroupForm() # Project readme readme_content, readme_exists = CodeBase.get_readme( '%s/data/%s' % (settings.MANTRA_PROJECT_ROOT, dataset_name)) sys.path.append(settings.MANTRA_PROJECT_ROOT) context = { **Mantra.find_dataset_metadata(dataset_name), 'readme_exists': readme_exists, 'readme_content': readme_content } context['files'] = CodeBase.get_files( '%s/data/%s' % (settings.MANTRA_PROJECT_ROOT, dataset_name)) context['directories'] = CodeBase.get_directories( '%s/data/%s' % (settings.MANTRA_PROJECT_ROOT, dataset_name)) trial_group_members, model_trials = Trial.get_trial_group_members( settings=settings, data_filter=dataset_name) context['task_list'] = Task.calculate_task_metadata(settings=settings, trials=model_trials) context['trial_groups'] = Trial.get_all_trial_group_metadata( settings=settings, trial_group_members=trial_group_members) context['trial_groups'].sort(key=lambda item: item['time'], reverse=True) context['form'] = form path = path.rstrip('/') codebase_data = CodeBase.get_code_data( blob_path='%s/data/%s/%s' % (settings.MANTRA_PROJECT_ROOT, dataset_name, path), path=path) context.update(codebase_data) return render(request, 'view_data_codebase.html', context)
def view_dataset_task(request, dataset_name, task_name): """ This view shows the dataset module page """ config = Mantra.get_config() data_list = Artefact.all(settings=settings, artefacts_folder=config['data_folder']) if dataset_name not in data_list: raise Http404("Dataset does not exist") # delete trial option - catch and process if request.method == 'POST': form = DeleteTrialGroupForm(request.POST) if form.is_valid(): Trial.remove_group_hash_from_contents(settings=settings, trial_group_hash=form.cleaned_data['trial_group_hash']) form = DeleteTrialGroupForm() # Project readme readme_content, readme_exists = CodeBase.get_readme('%s/data/%s' % (settings.MANTRA_PROJECT_ROOT, dataset_name)) sys.path.append(settings.MANTRA_PROJECT_ROOT) context = {**Mantra.find_dataset_metadata(dataset_name), 'readme_exists': readme_exists, 'readme_content': readme_content} context['files'] = CodeBase.get_files('%s/data/%s'% (settings.MANTRA_PROJECT_ROOT, dataset_name)) context['directories'] = CodeBase.get_directories('%s/data/%s'% (settings.MANTRA_PROJECT_ROOT, dataset_name)) trial_group_members, model_trials = Trial.get_trial_group_members(settings=settings, data_filter=dataset_name) task_trials = [trial for trial in model_trials if trial['task_name'] == task_name] trials_with_metadata = [] for trial in task_trials: trial.update({'time': datetime.datetime.utcfromtimestamp(int(str(trial['timestamp'])))}) try: trial['metadata'] = yaml.load(open('%s/trials/%s/trial_metadata.yml' % (settings.MANTRA_PROJECT_ROOT, trial['folder_name']), 'r').read()) trial['model_metadata'] = Mantra.find_model_metadata(trial['model_name']) if 'validation_loss' in trial['metadata']: trials_with_metadata.append(trial) except: # can't load yaml continue context['task_trials'] = trials_with_metadata context['task_trials'].sort(key=lambda item: item['metadata']['validation_loss'], reverse=False) context['task_name'] = task_name context['task_metadata'] = Mantra.find_task_metadata(task_name) context['trial_groups'] = Trial.get_all_trial_group_metadata(settings=settings, trial_group_members=trial_group_members) context['trial_groups'].sort(key=lambda item: item['time'], reverse=True) context['form'] = form return render(request, 'view_data_task.html', context)
def view_model_codebase(request, model_name, path): """ This view shows the codebase for a model """ # delete trial option - catch and process if request.method == 'POST': form = DeleteTrialGroupForm(request.POST) if form.is_valid(): Trial.remove_group_hash_from_contents(settings=settings, trial_group_hash=form.cleaned_data['trial_group_hash']) form = DeleteTrialGroupForm() config = Mantra.get_config() models_dir = os.path.join(settings.MANTRA_PROJECT_ROOT, config["models_folder"]) if os.path.isdir(models_dir): models_list = [o for o in os.listdir(models_dir) if os.path.isdir(os.path.join(models_dir, o))] else: models_list = [] if model_name not in models_list: raise Http404("Model does not exist") # Project readme readme_content, readme_exists = CodeBase.get_readme('%s/models/%s' % (settings.MANTRA_PROJECT_ROOT, model_name)) sys.path.append(settings.MANTRA_PROJECT_ROOT) context = {**Mantra.find_model_metadata(model_name), 'readme_exists': readme_exists, 'readme_content': readme_content} context['files'] = CodeBase.get_files('%s/models/%s'% (settings.MANTRA_PROJECT_ROOT, model_name)) context['directories'] = CodeBase.get_directories('%s/models/%s'% (settings.MANTRA_PROJECT_ROOT, model_name)) trial_group_members, model_trials = Trial.get_trial_group_members(settings=settings, model_filter=model_name) context['trial_groups'] = Trial.get_all_trial_group_metadata(settings=settings, trial_group_members=trial_group_members) context['trial_groups'].sort(key=lambda item: item['time'], reverse=True) context['form'] = form path = path.rstrip('/') codebase_data = CodeBase.get_code_data( blob_path='%s/models/%s/%s' % (settings.MANTRA_PROJECT_ROOT, model_name, path), path=path) context.update(codebase_data) return render(request, 'view_codebase.html', context)
def view_result(request, result_folder): """ This view shows a result of a trial, the model, the data etc """ result_metadata = yaml.load( open('%s/results/%s/result.yml' % (settings.MANTRA_PROJECT_ROOT, result_folder))) readme_content, readme_exists = CodeBase.get_readme( '%s/results/%s' % (settings.MANTRA_PROJECT_ROOT, result_folder)) context = { 'readme_exists': readme_exists, 'readme_content': readme_content } context['latest_media'] = Mantra.find_latest_trial_media(result_folder, result=True) context['description'] = result_metadata['description'] if '.' in context['description']: context['description'] = context['description'].split('.')[0] context['name'] = result_metadata['name'] trial_metadata = yaml.load( open('%s/results/%s/trial_metadata.yml' % (settings.MANTRA_PROJECT_ROOT, result_folder))) sys.path.append(settings.MANTRA_PROJECT_ROOT) context['model'] = {} context['data'] = {} context['result_folder'] = result_folder context['model'].update( Mantra.find_model_metadata(trial_metadata['model_name'])) context['data'].update( Mantra.find_dataset_metadata(trial_metadata['data_name'])) context['task'] = Mantra.find_task_metadata(trial_metadata['task_name']) # Obtain the hyperparameters if 'start_timestamp' in trial_metadata: trial_metadata.update({ 'start_time': datetime.datetime.utcfromtimestamp( int(str(trial_metadata['start_timestamp']))) }) if 'end_timestamp' in trial_metadata: trial_metadata.update({ 'end_time': datetime.datetime.utcfromtimestamp( int(str(trial_metadata['end_timestamp']))) }) hyperparameter_list = [] if 'hyperparameters' in trial_metadata: hyperparameter_list = hyperparameter_list + list( trial_metadata['hyperparameters'].keys()) occur = Counter([hyperparm for hyperparm in hyperparameter_list]) context['hyperparms'] = [i[0] for i in occur.most_common(5)] if 'hyperparameters' in trial_metadata: hyperparm_list = [] for hyperparm_no, hyperparm in enumerate(context['hyperparms']): if hyperparm in trial_metadata['hyperparameters']: hyperparameter_value = trial_metadata['hyperparameters'][ hyperparm] if context['hyperparms'][hyperparm_no] == 'image_dim': hyperparameter_value = '%s x %s' % ( hyperparameter_value[0], hyperparameter_value[1]) if isinstance(hyperparameter_value, list): hyperparameter_value_type = 'list' elif isinstance(hyperparameter_value, float): hyperparameter_value_type = 'float' else: hyperparameter_value_type = 'str' hyperparm_list.append({ 'value': hyperparameter_value, 'type': hyperparameter_value_type }) else: hyperparm_list.append({}) trial_metadata.update({'hyperparm_values': hyperparm_list}) else: trial_metadata.update( {'hyperparm_values': [None] * len(context['hyperparms'])}) context['hyperparms'] = [ hp.replace("_", " ").title() for hp in context['hyperparms'] ] context['model_trial'] = trial_metadata context['hyperparameter_dict'] = sorted( dict( zip(context['hyperparms'], context['model_trial']['hyperparm_values'])).items()) return render(request, 'view_result.html', context)