Kitware / DIVA

DIVA project repository
Other
18 stars 9 forks source link

Extendability for new types for the Sprokit pipeline #34

Closed johnhenning closed 5 years ago

johnhenning commented 5 years ago

Currently, there doesn't seem to be a good way to add more types to the Sprokit pipeline. The example pipelines use single components (ACT, R-C3D) to do activity detection, and the provided types are enough for those components. However, many systems built by DIVA participants have more components than just an activity detector and need to be able to define custom types for these components.

I think there should be an API for defining and registering new data types similar to how there is an API for registering components with Sprokit.

as6520 commented 5 years ago

In the global context: You can define a new data type in vital and register it here.

In application specific context: Once you have defined your application specific data types, you can create a new header (similar to kwiver_type_traits.h), register the types in that header and include it in your processes. An example is present here.

johnhenning commented 5 years ago

Is there a way to register them using python?

as6520 commented 5 years ago

To clarify, the data type is written in python not in c++ right ?

johnhenning commented 5 years ago

yes

as6520 commented 5 years ago

There is way to do it. I have not used it yet and I am not aware of an example where this functionality is demonstrated.

Sprokit wraps the data that is being sent across pipeline in datum and provides methods to access the datum. You can create a datum of the data that you want to push using the function new and push it to a port using push_datum_to_port_using_trait. On the receiving process, using grab_datum_from_port to grab the datum from the port and use get_datum to get the data back.

I can look into it and get back to you with a more concrete example as there might be some subtleties I might have missed which might cause things to not work. But essentially this would be the way to do it.

as6520 commented 5 years ago

The repo demonstrates this functionality. It was slightly easier that I had anticipated as you can define a new type trait in the process that you want to communicate and just send them across the pipeline using this new trait.

johnhenning commented 5 years ago

So you pass the type's class name as a string?

as6520 commented 5 years ago

Not necessarily. The function signatures are available here with docstring comments on type and port traits. When you add a type trait, you are specifying the name of the type trait and the canonical name of the type trait. Sprokit matches the canonical name to connect ports in the pipeline not the type name. You can create namespaces in the canonical name as shown here using ":" operator.

When a port trait is added, we use the type name not the canonical type name as the second argument. This allows different port name with the same type to be added without creating ambiguity.

as6520 commented 5 years ago

Closing this issue as it appears to be solved. Feel free to open it if there are any more questions.