<jupyter_start><jupyter_text>Chopping the Videos into Images<jupyter_code>def rename_image(video_path, img_slice):
    '''
    video_path: rgb_path
    img_slice: int
    '''
    img_slice = str(img_slice).zfill(2)
    
    return video_path.split('/')[-1].split('.')[0] +'_' + img_slice + '.png'
# train_or_val = 'train'
train_or_val = 'val'

resample_len = 32

for i in range(len(activities)):
    class_num = str(i)
    action_num = str(int(class_num) + 1)
    video_paths = glob.glob(os.path.join(DATA_PATH, 'RGB', train_or_val, 'a' + action_num+'_*avi'))
    print('class_num: {}, tot_num_of_actions: {}'.format(class_num, len(video_paths)))
    save_path = os.path.join(DATA_PATH, 'RGB_images',train_or_val, class_num)
    if not os.path.exists(save_path):
        os.mkdir(save_path)
    print(save_path)
    for video_path in video_paths:
#     video_path = video_paths[0]
        vid = av.open(video_path)
        images = []
        for packet in vid.demux():
            for frame in packet.decode():
                img = frame.to_image()  # PIL/Pillow image
        #         print(img)
                images.append(img)
        # images = np.array(images)
        start = int((len(images) - resample_len) /2)
        end = int((len(images) - resample_len) /2 + resample_len)
        save_images = images[start:end]
        for img_slice in range(len(save_images)):
#             print("image saved: {}".format(rename_image(video_path, img_slice)))
            img = save_images[img_slice]
            img.save(os.path.join(save_path, rename_image(video_path, img_slice)))
for video_path in video_paths:
#     video_path = video_paths[0]
    vid = av.open(video_path)
    images = []
    for packet in vid.demux():
        for frame in packet.decode():
            img = frame.to_image()  # PIL/Pillow image
    #         print(img)
            images.append(img)
    # images = np.array(images)
    start = int((len(images) - resample_len) /2)
    end = int((len(images) - resample_len) /2 + resample_len)
    save_images = images[start:end]
    for img_slice in range(len(save_images)):
        print("image saved: {}".format(rename_image(video_path, img_slice)))
        img = save_images[img_slice]
        img.save(os.path.join(save_path, rename_image(video_path, img_slice)))<jupyter_output>image saved: a27_s7_t1_color_00.png
image saved: a27_s7_t1_color_01.png
image saved: a27_s7_t1_color_02.png
image saved: a27_s7_t1_color_03.png
image saved: a27_s7_t1_color_04.png
image saved: a27_s7_t1_color_05.png
image saved: a27_s7_t1_color_06.png
image saved: a27_s7_t1_color_07.png
image saved: a27_s7_t1_color_08.png
image saved: a27_s7_t1_color_09.png
image saved: a27_s7_t1_color_10.png
image saved: a27_s7_t1_color_11.png
image saved: a27_s7_t1_color_12.png
image saved: a27_s7_t1_color_13.png
image saved: a27_s7_t1_color_14.png
image saved: a27_s7_t1_color_15.png
image saved: a27_s7_t1_color_16.png
image saved: a27_s7_t1_color_17.png
image saved: a27_s7_t1_color_18.png
image saved: a27_s7_t1_color_19.png
image saved: a27_s7_t1_color_20.png
image saved: a27_s7_t1_color_21.png
image saved: a27_s7_t1_color_22.png
image saved: a27_s7_t1_color_23.png
image saved: a27_s7_t1_color_24.png
image saved: a27_s7_t1_color_25.png
image saved: a27_s7_t1_color_26.png
image saved: a27_s7_t1_color[...]
{'fraction_non_alphanumeric': 0.11308805790108564, 'fraction_numerical': 0.05367913148371532, 'mean_word_length': 3.731811697574893, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '99118', 'license': 'MIT', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1305, 'n_words': 232, 'path': 'notebooks/Understanding_RGB_data.ipynb', 'repo_name': 'notha99y/Multimodal_human_actions', 'size': '3316'}