Commit 755967ae authored by Samuel GAIST's avatar Samuel GAIST

[algorithm] Cleanup example using v2 sequential algorithms

parent b7b4c693
Pipeline #24761 passed with stage
in 4 minutes and 52 seconds
......@@ -112,7 +112,10 @@ probabilistic component analysis (PCA):
.. code-block:: javascript
{
"schema_version": 2,
"language": "python",
"api_version": 2,
"type": "sequential",
"splittable": false,
"groups": [
{
......@@ -137,14 +140,18 @@ probabilistic component analysis (PCA):
"description": "Principal Component Analysis (PCA)"
}
The field `language` specifies the language in which the algorithm is
implemented. The field `splittable` indicates, whether the algorithm can be
parallelized into chunks or not. The field `parameters` lists the parameters
of the algorithm, describing both default values and their types. The field
`groups` gives information about the inputs and outputs of the algorithm.
They are provided into a list of dictionary, each element in this list being
associated to a database `channel`. The group, which contains outputs, is
the **synchronization channel**. By default, a loop is automatically performs
The field `schema_version` specifies which schema version must be used to
validate the file content. The field `api_version` specifies the version of the
API implemented by the algorithm. The field `type` specifies the type of the
algorithm. Depending on that, the execution model will change. The field
`language` specifies the language in which the algorithm is implemented. The
field `splittable` indicates, whether the algorithm can be parallelized into
chunks or not. The field `parameters` lists the parameters of the algorithm,
describing both default values and their types. The field `groups` gives
information about the inputs and outputs of the algorithm. They are provided
into a list of dictionary, each element in this list being associated to a
database `channel`. The group, which contains outputs, is the
**synchronization channel**. By default, a loop is automatically performed
by the platform on the synchronization channel, and user-code must not loop
on this group. In contrast, it is the responsibility of the user to load data
from the other groups. This is described in more details in the following
......@@ -550,7 +557,7 @@ its inputs, the algorithm would do:
class Algorithm:
def process(self, inputs, outputs):
def process(self, inputs, data_loaders, outputs):
# Iterate over all the unsynchronized data
while inputs.hasMoreData():
......@@ -611,7 +618,7 @@ keeps the others synchronized and iterate over all their data:
class Algorithm:
def process(self, inputs, outputs):
def process(self, inputs, data_loaders, utputs):
# Desynchronize the third input. From now on, inputs['desynchronized'].data
# and inputs['desynchronized'].data_index won't change
......@@ -741,19 +748,14 @@ Each output provides the following informations:
*(string)* Format of the data written on the output
And the following methods:
.. py:method:: createData()
Retrieve an initialized block of data corresponding to the data format of
the output
And the following method:
.. py:method:: write(data, end_data_index=None)
Write a block of data on the output
We'll look at the usage of those methods through some examples in the following
We'll look at the usage of this method through some examples in the following
sections.
......@@ -836,12 +838,9 @@ block for each image received on its inputs. This is the simplest case.
def process(self, inputs, outputs):
# Ask the output to create a data object according to its data format
data = outputs['features'].createData()
# Compute something from inputs['images'].data and inputs['labels'].data
# and store the result in 'data'
...
data = ...
# Write our data block on the output
outputs['features'].write(data)
......@@ -898,17 +897,14 @@ available.
class Algorithm:
def process(self, inputs, outputs):
def process(self, inputs, data_loaders, outputs):
# Use a criterion on the image to determine if we can perform our
# computation on it or not
if can_compute(inputs['images'].data):
# Ask the output to create a data object according to its data format
data = outputs['features'].createData()
# Compute something from inputs['images'].data and inputs['labels'].data
# and store the result in 'data'
...
data = ...
# Write our data block on the output
outputs['features'].write(data)
......@@ -985,7 +981,7 @@ the data block on the output.
self.previous_data_index = None # Data index of the input list during the
# processing of the previous image
def process(self, inputs, outputs):
def process(self, inputs, data_loaders, outputs):
# Determine if we already processed some image(s)
if self.data is not None:
# Determine if the label has changed since the last image we processed
......@@ -999,8 +995,7 @@ the data block on the output.
# Create a new block of data if necessary
if self.data is None:
# Ask the output to create a data object according to its data format
self.data = outputs['features'].createData()
self.data = ...
# Remember the label we are currently processing
self.current_label = inputs['labels'].data.name
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment