Creating a New Task

DeepDIVA covers already many common scenarios. It is however very likely that as researcher you will need to implement your own task. The easiest way to do it is copying the most similar task already implemented and then modifying it to fit your needs. In this tutorial we will copy from the image classification task.

Create Your Module

Copy and entire module and rename it as you like your task to be called. Keep in mind that names of modules follow the snake_case formatting.

cp -r ./template/runner/image_classification ./template/runner/my_task

Fix the File names

Each task has to have file which exposes a static method single_run(). This file name MUST be the very same of the module name. In other words, the name of this file has to be the same of the folder in which it is contained.

cd template/runner/my_task
mv image_classification.py my_task.py

Inside this file there is a class with the same name of the file but with CamelCase convention. This is mandatory. Fix the class with (in this case) MyTask instead of ImageClassification.

Note: this is not strictly necessary, depending on the situation, however, do not forget replacing the lines:

# Delegated
from template.runner.image_classification import evaluate, train

with

# Delegated
from template.runner.my_task import evaluate, train

Update the __init__.py File of Your Task

In Python is of utmost importance to keep the __init__.py files updated. Hence we need to update the module file replacing

from .my_task import ImageClassification
__all__ = ['ImageClassification']

with

from .my_task import MyTask
__all__ = ['MyTask']

Update the __init__.py File of All Runner Tasks

Additionally, we need to import the newly implemented module in the __init__.py of the ./template/runner module. Therefore we need to add to ./template/runner/__init__.py the following line:

from .my_task import MyTask

and update the __all__ variable by adding "MyTask" to it.

Add the New Task to Command Line Argument Choices

It is now necessary to add the new module as possible value for the --runner-class command line argument. We know that having to do this manually makes this step ugly. We will eventually use introspection to automate this step.

In the file DeepDIVA/template/CL_arguments.py look for the variable runner_class_options inside the _general_parameters() function. Add your task to the list with snake_case convention (see the other names in the list).

Run Your Task!

At this point you are good to go! Verify that everything went well by running the task you copied and then runnning it again by modifying (or adding if you were using image_classification) the parameter --runner-class with value my_task.

Example:

python RunMe.py --dataset-folder /path/to/dataset

and if everything works try:

python RunMe.py --dataset-folder /path/to/dataset --runner-class my_task

If everything works without errors you succeeded in implementing your own task. Now you can go and modify all files in ./template/runner/my_task to fit your needs. Enjoy!