Beispiel #1
0
    def from_labels(
        cls,
        training: Union[Text, sleap.Labels],
        validation: Union[Text, sleap.Labels, float],
        test: Optional[Union[Text, sleap.Labels]] = None,
        video_search_paths: Optional[List[Text]] = None,
    ) -> "DataReaders":
        """Create data readers from sleap.Labels datasets as data providers."""

        if isinstance(training, str):
            print("video search paths: ", video_search_paths)
            training = sleap.Labels.load_file(training,
                                              video_search=video_search_paths)
            print(training.videos)

        if isinstance(validation, str):
            validation = sleap.Labels.load_file(
                validation, video_search=video_search_paths)
        elif isinstance(validation, float):
            training, validation = split_labels(training, [-1, validation])

        if isinstance(test, str):
            test = sleap.Labels.load_file(test,
                                          video_search=video_search_paths)

        test_reader = None
        if test is not None:
            test_reader = LabelsReader.from_user_instances(test)

        return cls(
            training_labels_reader=LabelsReader.from_user_instances(training),
            validation_labels_reader=LabelsReader.from_user_instances(
                validation),
            test_labels_reader=test_reader,
        )
Beispiel #2
0
    def predict(
        self,
        data_provider: Provider,
        make_instances: bool = True,
        make_labels: bool = False,
    ):
        t0_gen = time.time()

        if isinstance(data_provider, sleap.Labels):
            data_provider = LabelsReader(data_provider)
        elif isinstance(data_provider, sleap.Video):
            data_provider = VideoReader(data_provider)

        generator = self.predict_generator(data_provider)

        if make_instances or make_labels:
            lfs = self.make_labeled_frames_from_generator(generator, data_provider)
            elapsed = time.time() - t0_gen
            logger.info(
                f"Predicted {len(lfs)} labeled frames in {elapsed:.3f} secs [{len(lfs)/elapsed:.1f} FPS]"
            )

            if make_labels:
                return sleap.Labels(lfs)
            else:
                return lfs

        else:
            examples = list(generator)
            elapsed = time.time() - t0_gen
            logger.info(
                f"Predicted {len(examples)} examples in {elapsed:.3f} secs [{len(examples)/elapsed:.1f} FPS]"
            )

            return examples
Beispiel #3
0
    def predict(
        self,
        data_provider: Provider,
        make_instances: bool = True,
        make_labels: bool = False,
    ):
        if isinstance(data_provider, sleap.Labels):
            data_provider = LabelsReader(data_provider)
        elif isinstance(data_provider, sleap.Video):
            data_provider = VideoReader(data_provider)
        generator = self.predict_generator(data_provider)

        if make_instances or make_labels:
            lfs = self.make_labeled_frames_from_generator(generator, data_provider)
            if make_labels:
                return sleap.Labels(lfs)
            else:
                return lfs

        return list(generator)