MCPcopy Create free account
hub / github.com/apple/ml-4m / MetadataTransform

Class MetadataTransform

fourm/data/modality_transforms.py:843–1006  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

841
842
843class MetadataTransform(AbstractTransform):
844
845 def __init__(self,
846 special_vmin: int = 0,
847 special_vmax: int = 999,
848 shuffle: bool = True,
849 random_trunc: bool = False,
850 return_chunks: bool = True,
851 return_raw: bool = False,
852 image_dim_bin_size: int = 32,):
853 """Metadata transform that takes in a metadata dictionary and converts
854 it into a string, or list of strings (for chunked span masking).
855 Uses special tokens v1 to denote metadata types, and v0 for their values.
856
857 Args:
858 special_vmin: Minimum value for special tokens
859 special_vmax: Maximum value for special tokens
860 shuffle: Whether to shuffle the metadata order
861 random_trunc: Whether to randomly truncate the returned metadata
862 return_chunks: Whether to return a list of strings (for chunked span masking),
863 or a single string with all metadata concatenated
864 return_raw: Whether to return the raw metadata dictionary
865 """
866 self.special_vmin = special_vmin
867 self.special_vmax = special_vmax
868 self.shuffle = shuffle
869 self.random_trunc = random_trunc
870 self.return_chunks = return_chunks
871 self.return_raw = return_raw
872 self.image_dim_bin_size = image_dim_bin_size
873
874 # Explicit map to make sure that additional entries do not change existing IDs
875 # TODO: Make this work with other text tokenizers
876 self.metadata_id_map = {
877 'original_width': 'v1=0',
878 'original_height': 'v1=1',
879 'caption_n_chars': 'v1=2',
880 'caption_n_words': 'v1=3',
881 'caption_n_sentences': 'v1=4',
882 'n_humans': 'v1=5',
883 'n_sam_instances': 'v1=6',
884 'n_coco_instances': 'v1=7',
885 'coco_instance_diversity': 'v1=8',
886 'colorfulness': 'v1=9',
887 'brightness': 'v1=10',
888 'contrast': 'v1=11',
889 'saturation': 'v1=12',
890 'entropy': 'v1=13',
891 'walkability': 'v1=14',
892 'objectness': 'v1=15',
893 'semantic_diversity': 'v1=16',
894 'geometric_complexity': 'v1=17',
895 'occlusion_score': 'v1=18',
896 'watermark_score': 'v1=19',
897 'aesthetic_score': 'v1=20',
898 }
899 self.id_metadata_map = {v: k for k, v in self.metadata_id_map.items()}
900

Callers 2

plotting_utils.pyFile · 0.90
modality_info.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected