def setup_project(): """ Add a new project to the config file. Can also be used for updating an existing project. """ data = request.form name = data['projectName'] path = data['path'] # Initialize project directory if not os.path.exists(path): os.mkdir(path) # Update project config try: # Check for existing config file config = utils.load_project_config(path) old_name = config['name'] config['name'] = name except FileNotFoundError: # Setup new project config config = { 'name': name, 'date_created': datetime.date.today().isoformat(), 'classes': {}, 'use_gpu': False, 'temporal': False, 'video_recording': { 'countdown': 3, 'recording': 5, }, } old_name = None utils.write_project_config(path, config) # Setup directory structure for split in SPLITS: videos_dir = directories.get_videos_dir(path, split) if not os.path.exists(videos_dir): os.mkdir(videos_dir) # Update overall projects config file projects = utils.load_project_overview_config() if old_name and old_name in projects: del projects[old_name] projects[name] = { 'path': path, } utils.write_project_overview_config(projects) return redirect(url_for('project_details', project=name))
def edit_class(project, class_name): """ Edit the class name and tags for an existing class in the given project. """ project = urllib.parse.unquote(project) class_name = urllib.parse.unquote(class_name) path = utils.lookup_project_path(project) # Get new class name and tags new_class_name, new_tag1, new_tag2 = utils.get_class_name_and_tags( request.form) # Update project config config = utils.load_project_config(path) del config['classes'][class_name] config['classes'][new_class_name] = [new_tag1, new_tag2] utils.write_project_config(path, config) # Update directory names data_dirs = [] for split in SPLITS: data_dirs.extend([ directories.get_videos_dir(path, split), directories.get_frames_dir(path, split), directories.get_tags_dir(path, split), ]) # Feature directories follow the format <dataset_dir>/<split>/<model>/<num_layers_to_finetune>/<label> features_dir = directories.get_features_dir(path, split) model_dirs = [ os.path.join(features_dir, model_dir) for model_dir in os.listdir(features_dir) ] data_dirs.extend([ os.path.join(model_dir, tuned_layers) for model_dir in model_dirs for tuned_layers in os.listdir(model_dir) ]) logreg_dir = directories.get_logreg_dir(path) data_dirs.extend([ os.path.join(logreg_dir, model_dir) for model_dir in os.listdir(logreg_dir) ]) for base_dir in data_dirs: class_dir = os.path.join(base_dir, class_name) if os.path.exists(class_dir): new_class_dir = os.path.join(base_dir, new_class_name) os.rename(class_dir, new_class_dir) return redirect(url_for('project_details', project=project))
def remove_class(project, class_name): """ Remove the given class from the config file of the given project. No data will be deleted. """ project = urllib.parse.unquote(project) class_name = urllib.parse.unquote(class_name) path = utils.lookup_project_path(project) # Update project config config = utils.load_project_config(path) del config['classes'][class_name] utils.write_project_config(path, config) return redirect(url_for("project_details", project=project))
def add_class(project): """ Add a new class to the given project. """ project = urllib.parse.unquote(project) path = utils.lookup_project_path(project) # Get class name and tags class_name, tag1, tag2 = utils.get_class_name_and_tags(request.form) # Update project config config = utils.load_project_config(path) config['classes'][class_name] = [tag1, tag2] utils.write_project_config(path, config) # Setup directory structure for split in SPLITS: videos_dir = directories.get_videos_dir(path, split, class_name) if not os.path.exists(videos_dir): os.mkdir(videos_dir) return redirect(url_for("project_details", project=project))
def edit_class(project, class_name): """ Edit the class name and tags for an existing class in the given project. """ project = urllib.parse.unquote(project) class_name = urllib.parse.unquote(class_name) path = utils.lookup_project_path(project) # Get new class name and tags new_class_name, new_tag1, new_tag2 = utils.get_class_name_and_tags(request.form) # Update project config config = utils.load_project_config(path) del config['classes'][class_name] config['classes'][new_class_name] = [new_tag1, new_tag2] utils.write_project_config(path, config) # Update directory names prefixes = ['videos', 'features', 'frames', 'tags'] for split in utils.SPLITS: for prefix in prefixes: main_dir = os.path.join(path, f'{prefix}_{split}') class_dir = os.path.join(main_dir, class_name) if os.path.exists(class_dir): new_class_dir = os.path.join(main_dir, new_class_name) os.rename(class_dir, new_class_dir) logreg_dir = os.path.join(path, 'logreg') class_dir = os.path.join(logreg_dir, class_name) if os.path.exists(class_dir): new_class_dir = os.path.join(logreg_dir, new_class_name) os.rename(class_dir, new_class_dir) return redirect(url_for("project_details", project=project))