# Tutorial¶

This tutorial introduces the general workflow when using TensorVision. Examples can be found in the Modell Zoo repository.

## Basics¶

Train a model:

tv-train --hypes config.json


Evaluate a model:

python eval.py


Flags:

• --hypes=myconfig.json
• --name=myname

## Workflow¶

Each time you get a new task

### Create JSON file¶

Create a json file (e.g. cifar10_cnn.json). It has at least the following content:

{
"model": {
"input_file": "examples/inputs/cifar10_input.py",
"architecture_file" : "examples/networks/cifar_net.py",
"objective_file" : "examples/objectives/softmax_classifier.py",
"optimizer_file" : "examples/optimizer/exp_decay.py"
}
}


The input_file contains the path to a Python file. This Python file has to have a function inputs(hypes, q, phase, data_dir).

The parameters of inputs are:

• q: A queue (e.g. FIFOQueue)
• phase: Either train or val
• data_dir: Path to the data. This can be set with TV_DIR_DATA.

The expected return value is a tuple (xs, ys), where x is a list of features and y is a list of labels.

The architecture_file contains the architecture of the network. It has to have the function inference(hypes, images, train=True), which takes image tensors creates a computation graph to produce logits

The objective_file contains task spezific code od the model. It has to implement the following functions:

• decoder(hypes, images, train=True)
• loss(hypes, decoder, labels)
• evaluation(hypes, decoder, labels)

The optimizer_file contains the path to a Python file. This Python file has to have a function training(H, loss, global_step, learning_rate). It defines how one tries to find a minimum of the loss function. Additionally it should provide a function get_learning_rate(hype, global_step), which returns the current learning rate at each step.

## Scripts¶

TensorVision brings some scripts which you can use:

• tv-train: Trains, evaluates and saves the model network using a queue.
• tv-continue: Continues training of a model from logdir.
• tv-analyze: Evaluates the model.

## Hypes file¶

TensorVision makes use of a configuration file for each project. As it was originally intended to have hyperparameters of models, it is commonly called “hypes file” or hypes.json throughout this project.

This configuration file allows you to adjust given networks easily to new problem domains.

### data¶

It is recommended to create one json file for the training data sources as well as one for the testing data sources. Each file is a list of dictionaries, where each dictionary has the keys raw and mask. For example, your trainfiles.json could look like this:

[
{
"raw": "/home/moose/GitHub/MediSeg/DATA/OP1/img_00.png",
},
{
"raw": "/home/moose/GitHub/MediSeg/DATA/OP1/img_01.png",
},
{
"raw": "/home/moose/GitHub/MediSeg/DATA/OP1/img_02.png",
}
]


"data": {
"train": "../../DATA/trainfiles.json",
"test": "../../DATA/testfiles.json"
},


### classes¶

"classes": [
{"name": "background",
"colors": ["#000000"],
"output": "#ff000000"},
{"name": "instrument",
"colors": ["#464646", "#a0a0a0", "#ffffff", "default"],
"output": "#00ff007f"}
]