borglab / gtsfm

End-to-end SFM framework based on GTSAM
Other
411 stars 50 forks source link

Delayed expected types #238

Open travisdriver opened 3 years ago

travisdriver commented 3 years ago

I think it would be useful for any function which has a Delayed object as either an input or an output, to specify the expected type of the variable after task completion in the doc string. This will reduce the need to follow a chain of function calls to figure out the expected type during development. For example, in the DetectorDescriptorBase class, instead of

def create_computation_graph(self, image_graph: Delayed) -> Tuple[Delayed, Delayed]:
        """
        Generates the computation graph for detections and their descriptors.

        Args:
            image_graph: computation graph for a single image (from a loader).

        Returns:
            Delayed tasks for detections.
            Delayed task for corr. descriptors.
        """
        # get delayed object, cannot separate two arguments immediately
        joint_graph = dask.delayed(self.detect_and_describe)(image_graph)

        keypoints_graph = joint_graph[0]
        descriptor_graph = joint_graph[1]

        return keypoints_graph, descriptor_graph

It could be something like

def create_computation_graph(self, image_graph: Delayed) -> Tuple[Delayed, Delayed]:
        """
        Generates the computation graph for detections and their descriptors.

        Args:
            image_graph: computation graph for a single image (expects Image).

        Returns:
            Delayed tasks for detections (expects Keypoints).
            Delayed task for corr. descriptors (expects np.ndarray).
        """
        # get delayed object, cannot separate two arguments immediately
        joint_graph = dask.delayed(self.detect_and_describe)(image_graph)

        keypoints_graph = joint_graph[0]
        descriptor_graph = joint_graph[1]

        return keypoints_graph, descriptor_graph
akshay-krishnan commented 3 years ago

Lets all take some time to update documentation when we can :)

travisdriver commented 3 years ago

Agreed :)