| import json |
| from preprocess_pkg.clip4clip import PiaTemplateJson2UniversalFormat, MakePiaTemplateJsonFromClassifiedFolders, MainUtils, CLIP4ClipPrep, SyntheticCaptionGeneration |
| import os |
|
|
| if __name__ == "__main__": |
| MU = MainUtils() |
| skip_folder = [] |
|
|
| NAS_PATH = "/home/piawsa6000/nas192" |
| NAS_PATH = "/mnt/nas192" |
| input_path = os.path.join(NAS_PATH, "Research_materials/PIA_clip_dataset/CLIP4Clip_format/PIA_clip_outdoor_v1/classified_videos") |
| pia_template_json_output_path = "./" |
| universal_format_output_path = "pia_template_universal_format.json" |
|
|
|
|
| folder2classmapping = { |
| "fire": "fire", |
| "falldown": "falldown", |
| "normal": "normal", |
| "violence": "violence" |
| } |
|
|
|
|
| json_out_path = MakePiaTemplateJsonFromClassifiedFolders(input_path, |
| pia_template_json_output_path, |
| skip_folder, |
| folder2classmapping, |
| train_split_param = 0.05, |
| test_split_param = 0.5, |
| multi_process_copy = True).run() |
|
|
| universal_format = PiaTemplateJson2UniversalFormat(json_out_path).get_universal_format() |
|
|
|
|
| json_out_path = MU._save_as_json(universal_format, |
| pia_template_json_output_path, |
| json_name = "pia_template_universal_format.json") |
|
|
|
|
| C4C = CLIP4ClipPrep(json_out_path) |
| C4C.make_train_val_test() |
| C4C.make_class_wise_cfg() |
| C4C._video_caption_dict_process() |
| C4C.make_formated_caption() |
| C4C.checker_train_val_test() |
|
|
| synthetic_template_placeholder_caption = "./synthethic_caption_template_placeholder.json" |
|
|
| generator = SyntheticCaptionGeneration(synthetic_template_placeholder_caption) |
|
|
|
|
| C4C = CLIP4ClipPrep(None, output_name = "synthethic_caption_CLIP4CLIP") |
|
|
|
|
| for video_id, data in universal_format.items(): |
| caption = generator.make_caption(data["category"].lower()) |
| C4C._video_synthetic_caption_dict_process(video_id, caption) |
| C4C.make_formated_caption() |