Skip to main content

Project initialization

Learn how to initialize a project with and without labels

Project initialization using Python code provides the same functionality as running the init command in the CLI. If you prefer using the CLI, you can refer to the Quick import data & labels guide.

Steps to initialize a project without labels

Open in Colab
  1. Choose the images you want to import. For example, you can use the glob function to find all the files with the ".jpg" extension in your current working directory, including subdirectories. Customize the logic as needed to include specific files.

    from pathlib import Path

    image_files = list(Path.cwd().glob("**/*.jpg"))
  2. Specify the directory where you want to store the Encord Active project. It is recommended to keep multiple projects within the same directory for easy navigation within the UI.

    projects_dir = Path("path/to/where/you/store/projects")
  3. Create the project. Note that the symlinks option determines whether files are copied (symlinks=False) or referenced using symlinks to save disk space (symlinks=True).

    from encord_active.lib.project.local import init_local_project

    project_path = init_local_project(
    files=image_files,
    target=projects_dir,
    project_name="<your project title>",
    symlinks=True,
    )
  4. Run a metric to ensure proper functioning of the UI.

    from encord_active.lib.metrics.execute import execute_metrics
    from encord_active.lib.metrics.heuristic.img_features import AreaMetric

    execute_metrics(
    selected_metrics=[AreaMetric()],
    data_dir=project_path,
    use_cache_only=True,
    )

    Alternatively, you can run all metrics that do not depend on any labels using the following code snippet:

    from encord_active.lib.metrics.execute import run_metrics_by_embedding_type
    from encord_active.lib.metrics.types import EmbeddingType

    run_metrics_by_embedding_type(
    EmbeddingType.IMAGE,
    data_dir=project_path,
    use_cache_only=True,
    )

After completing these steps, you can launch the application by using the following CLI command and access the project:

encord-active start -t "path/to/where/you/store/projects"

Steps to initialize a project with labels

Open in Colab

If you have previously defined a LabelTransformer as explained in the Quick import data & labels guide, you can utilize it in the project initialization process. To include labels, you need to provide the transformer object and the corresponding label files to the init_local_project function.

  1. Choose the images and label files you want to import. For example, you can use the glob function to find all the files with the ".jpg" extension and label files with the ".json" extension in your current working directory, including subdirectories. Customize the logic as needed to include specific files.

    from pathlib import Path

    image_files = list(Path.cwd().glob("**/*.jpg"))
    label_files = list(Path.cwd().glob("**/*.json"))
  2. Define a class that implements the LabelTransformer interface and handles the parsing of labels. For instance, you can refer to the implementation of the BBoxTransformer class. Instantiate this class to utilize it for including labels in your project.

    label_transformer = BBoxTransformer()
    tip

    Check out more label transformer examples in the examples section of Encord Active's GitHub repository.

  3. Specify the directory where you want to store the Encord Active project. It is recommended to keep multiple projects within the same directory for easy navigation within the UI.

    projects_dir = Path("path/to/where/you/store/projects")
  4. Create the project. Note that the symlinks option determines whether files are copied (symlinks=False) or referenced using symlinks to save disk space (symlinks=True).

    from encord_active.lib.project.local import init_local_project

    project_path = init_local_project(
    files = image_files,
    target = projects_dir,
    project_name = "<your project title>",
    symlinks = True,
    label_transformer=label_transformer,
    label_paths=label_files,
    )
  5. Run a metric to ensure proper functioning of the UI.

    from encord_active.lib.metrics.execute import execute_metrics
    from encord_active.lib.metrics.heuristic.img_features import AreaMetric

    execute_metrics(
    selected_metrics=[AreaMetric()],
    data_dir=project_path,
    use_cache_only=True,
    )

    Alternatively, you can run all metrics related to labels using the following code snippet:

    from encord_active.lib.metrics.execute import run_metrics_by_embedding_type
    from encord_active.lib.metrics.types import EmbeddingType

    run_metrics_by_embedding_type(
    EmbeddingType.OBJECT,
    data_dir=project_path,
    use_cache_only=True,
    )

    run_metrics_by_embedding_type(
    EmbeddingType.CLASSIFICATION,
    data_dir=project_path,
    use_cache_only=True,
    )

After completing these steps, you can launch the application by using the following CLI command and access the project:

encord-active start -t "path/to/where/you/store/projects"