MCPcopy Create free account
hub / github.com/Netflix/void-model / ImageVideoControlDataset

Class ImageVideoControlDataset

videox_fun/data/dataset_image_video.py:841–1067  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

839
840
841class ImageVideoControlDataset(Dataset):
842 def __init__(
843 self,
844 ann_path, data_root=None,
845 video_sample_size=512, video_sample_stride=4, video_sample_n_frames=16,
846 image_sample_size=512,
847 video_repeat=0,
848 text_drop_ratio=0.1,
849 enable_bucket=False,
850 video_length_drop_start=0.0,
851 video_length_drop_end=1.0,
852 enable_inpaint=False,
853 ):
854 # Loading annotations from files
855 print(f"loading annotations from {ann_path} ...")
856 if ann_path.endswith('.csv'):
857 with open(ann_path, 'r') as csvfile:
858 dataset = list(csv.DictReader(csvfile))
859 elif ann_path.endswith('.json'):
860 dataset = json.load(open(ann_path))
861 else:
862 raise ValueError(f"Unsupported annotation file format: {ann_path}. Only .csv and .json files are supported.")
863
864 self.data_root = data_root
865
866 # It's used to balance num of images and videos.
867 self.dataset = []
868 for data in dataset:
869 if data.get('type', 'image') != 'video':
870 self.dataset.append(data)
871 if video_repeat > 0:
872 for _ in range(video_repeat):
873 for data in dataset:
874 if data.get('type', 'image') == 'video':
875 self.dataset.append(data)
876 del dataset
877
878 self.length = len(self.dataset)
879 print(f"data scale: {self.length}")
880 # TODO: enable bucket training
881 self.enable_bucket = enable_bucket
882 self.text_drop_ratio = text_drop_ratio
883 self.enable_inpaint = enable_inpaint
884
885 self.video_length_drop_start = video_length_drop_start
886 self.video_length_drop_end = video_length_drop_end
887
888 # Video params
889 self.video_sample_stride = video_sample_stride
890 self.video_sample_n_frames = video_sample_n_frames
891 self.video_sample_size = tuple(video_sample_size) if not isinstance(video_sample_size, int) else (video_sample_size, video_sample_size)
892 self.video_transforms = transforms.Compose(
893 [
894 transforms.Resize(min(self.video_sample_size)),
895 transforms.CenterCrop(self.video_sample_size),
896 transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5], inplace=True),
897 ]
898 )

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected