Exemple #1
0
def test_item_is_valid(channel_files: List[Optional[str]],
                       numerical_features: torch.Tensor,
                       categorical_features: torch.Tensor,
                       is_valid: bool) -> None:
    c = ScalarDataSource(channel_files=channel_files,
                         numerical_non_image_features=numerical_features,
                         categorical_non_image_features=categorical_features,
                         label=torch.empty(0),
                         metadata=GeneralSampleMetadata(id="foo"))
    assert c.is_valid() == is_valid
 def _create(pos: int) -> ScalarDataSource:
     z = torch.empty(0)
     return ScalarDataSource(metadata=GeneralSampleMetadata(
         id="", sequence_position=pos),
                             categorical_non_image_features=z,
                             label=z,
                             numerical_non_image_features=z,
                             channel_files=[])
 def apply_source(source: ScalarDataSource) -> ScalarDataSource:
     new_features = (source.numerical_non_image_features -
                     self.mean) / self.std
     zero_or_nan = (self.std == 0.0) + torch.isnan(self.std)
     new_features[zero_or_nan] = source.numerical_non_image_features[
         zero_or_nan]
     return source.clone_with_overrides(
         numerical_non_image_features=new_features)