classPiiClassIndexMapper
#include <PiiClassIndexMapper.h>
An operation that maps indices into other indices.
Inherits PiiDefaultOperation
Description
This operation can make use of a special data structure, classInfoMap, which stores information about class indices. Its purpose is to map a continuous range of class indices to a possibly non-continuos range. The operation is useful if classes need to be deleted and added while the remaining ones must retain their indices.
Let us assume we initially have a continuous range of class indices 0-3. After deleting class 1 we have only three classes left (0, 2, 3). Since classifiers use a continuous range of indices (0, 1, 2) we need to map 1 and 2 to 2 and 3 to retain the old indices. Here's how:
PiiOperation* mapper = engine.createOperation("PiiClassIndexMapper"); mapper->setProperty("classIndexMap", QVariantList() << 0 << 2 << 3);
The operation makes it easy to connect additional information to classes. Let us assume that we later changed the order of classes 0 and 2. Here's what we need to do:
// The normal stuff for converting class indices mapper->setProperty("classIndexMap", QVariantList() << 2 << 0 << 3); // Include additional information QVariantMap classInfoMap; classInfoMap["classNames"] = QStringList() << "two" << "zero" << "three"; mapper->setProperty("classInfoMap", classInfoMap);
As a result, the class name output will emit "two" for
any incoming 0, "zero" for ones, "three" for twos, and "Unknown"
for anything else.
It is also possible to map multiple indices into one but still include the class information only once. Here's how:
// Mapping table: // 0-2 -> 1 // 3 -> 5 // 4 -> 2 // 5 -> 0 mapper->setProperty("classIndexMap", QVariantList() << 1 << 1 << 1 << 5 << 2 << 0); QVariantMap classInfoMap; // Now we only have four classes and we don't want to repeat the class names. classInfoMap["classNames"] = QStringList() << "zero" << "one" << "two" << "five"; // These indices map the values in classIndexMap back to classNames classInfoMap["classIndices"] = QVariantList() << 0 << 1 << 2 << 5; mapper->setProperty("classInfoMap", classInfoMap);
The result:
|
Input |
class index |
class name |
list index |
|---|---|---|---|
|
0 |
1 |
one |
1 |
|
1 |
1 |
one |
1 |
|
2 |
1 |
one |
1 |
|
3 |
5 |
five |
3 |
|
4 |
2 |
four |
2 |
|
5 |
0 |
zero |
0 |
Inputs
Outputs
classIndices list (see classInfoMap).
Properties
|
QVariantList
|
The input-output mapping. |
|
QVariantMap
|
Additional information for classes. |
Constructors and destructor
Public member functions
|
QVariantList
|
( )
|
|
QVariantMap
|
( )
|
|
void
|
(
|
|
void
|
(
|
Protected member functions
|
virtual void
|
( )
Executes one round of processing. |
Property details
-
QVariantList classIndexMap
[read, write]The input-output mapping.
The length of this list should be equal to the maximum possible input class index plus one. Each value in this list specifies the output value for the corresponding input class index. The following example configures the mapper so that each incoming zero is converted to one and vice versa. If the input index is below zero or exceeds the size of the class index map, zero will be emitted.
// Map zero to one and one to zero mapper->setProperty("classIndexMap", QVariantList() << 1 << 0);
-
QVariantMap classInfoMap
[read, write]Additional information for classes.
The info map contains a number of QVariantLists that provide additional information for the classes. Each of the lists must be of equal length.
-
classIndices- indices of the classes. The indices may not be zero-based and may skip values. A QVariantList whose elements are convertible to ints. If this value is present, the indices in classIndexMap are mapped back to list indices using the values in this list. The output oflist indexis meaningful only if this value is set. -
classNames- the names of the classes. A QStringList.
-
Function details
-
PiiClassIndexMapper
() -
QVariantList classIndexMap
() -
QVariantMap classInfoMap
() -
void setClassIndexMap
(- const QVariantList & classIndexMap
-
void setClassInfoMap
(- const QVariantMap & classInfoMap
-
virtual void process
()[protected, virtual]Executes one round of processing.
This function is invoked by the processor if the necessary preconditions for a new processing round are met. This function does all the necessary calculations to create output objects and sends them to output sockets.
Calls to process(), syncEvent(), and setProperty() are synchronized and cannot occur simultaneously. PiiDefaultOperation ensures this by locking processLock() for reading before calling process().
Note: With time-consuming operations, one should occasionally check that the operation hasn't been interrupted, i.e. that state() returns
Running.Exceptions
- PiiExecutionException
-
whenever an unrecoverable error occurs during a processing round, the operation is interrupted, or finishes execution due to end of input data.
Reimplemented from PiiDefaultOperation.
Add a note
Not a single note added yet. Be the first, add yours.