FaceForensics++数据集处理

这篇文章是对官方的数据集分成train、test、val的脚本。
纯原创,可能有些部分比较繁琐,大佬们嘴下留情。

一共分两部分,对真视频的处理脚本和对假视频的处理脚本

首先

        将官方给的三个json保存到相应目录里。
官网地址:GitCode - 全球开发者的开源社区,开源代码托管平台

接下来

        对真视频的处理:需要改的地方就是你的数据集地址以及处理之后的地址。

import os
import json
import shutil

with open('test.json', 'r', encoding='utf-8') as f_test:
    data_test = json.load(f_test)
with open('train.json', 'r', encoding='utf-8') as f_train:
    data_train = json.load(f_train)
with open('val.json', 'r', encoding='utf-8') as f_val:
    data_val = json.load(f_val)

source_folder = '/FaceForensics++/C40/original_sequences/youtube/c40/videos'
test_target_folder = '/FaceForensics++/C40/deelvideo/true/test/videos'
train_target_folder = '/FaceForensics++/C40/deelvideo/true/train/videos'
val_target_folder = '/FaceForensics++/C40/deelvideo/true/val/videos'

if not os.path.exists(test_target_folder):
    os.makedirs(test_target_folder)

for item in data_test:
    for i in item:
        file_name = f"{i}.mp4"
        source_file_path = os.path.join(source_folder, file_name)
        target_file_path = os.path.join(test_target_folder, file_name)
        if os.path.exists(source_file_path):
            shutil.copy(source_file_path, target_file_path)

if not os.path.exists(train_target_folder):
    os.makedirs(train_target_folder)

for item in data_train:
    for i in item:
        file_name = f"{i}.mp4"
        source_file_path = os.path.join(source_folder, file_name)
        target_file_path = os.path.join(train_target_folder, file_name)
        if os.path.exists(source_file_path):
            shutil.copy(source_file_path, target_file_path)

if not os.path.exists(val_target_folder):
    os.makedirs(val_target_folder)

for item in data_val:
    for i in item:
        file_name = f"{i}.mp4"
        source_file_path = os.path.join(source_folder, file_name)
        target_file_path = os.path.join(val_target_folder, file_name)
        if os.path.exists(source_file_path):
            shutil.copy(source_file_path, target_file_path)

然后

        对假视频的处理:同样要去修改source_folder、test_target_folder、train_target_folder、val_target_folder这三个地址,不过这里需要对每个操作方法都要重新修改一下地址,这里我没做一个遍历,只能手动改一下了。例如:/FaceForensics++/C40/manipulated_sequences/NeuralTextures/c40/videos,这个地址是对NeuralTextures进行的处理,处理完修改地址中的NeuralTextures改成Deepfakes就可以了。

import os
import json
import shutil

with open('test.json', 'r', encoding='utf-8') as f_test:
    data_test = json.load(f_test)
with open('train.json', 'r', encoding='utf-8') as f_train:
    data_train = json.load(f_train)
with open('val.json', 'r', encoding='utf-8') as f_val:
    data_val = json.load(f_val)

source_folder = '/FaceForensics++/C40/manipulated_sequences/NeuralTextures/c40/videos'
test_target_folder = '/FaceForensics++/C40/deelvideo/false/NeuralTextures/test/videos'
train_target_folder = '/FaceForensics++/C40/deelvideo/false/NeuralTextures/train/videos'
val_target_folder = '/FaceForensics++/C40/deelvideo/false/NeuralTextures/val/videos'

if not os.path.exists(test_target_folder):
    os.makedirs(test_target_folder)

for item in data_test:
    num = 0
    for i in item:
        file_name = f"{item[num]}_{item[1-num]}.mp4"
        source_file_path = os.path.join(source_folder, file_name)
        target_file_path = os.path.join(test_target_folder, file_name)
        if os.path.exists(source_file_path):
            shutil.copy(source_file_path, target_file_path)
        num = num + 1

if not os.path.exists(train_target_folder):
    os.makedirs(train_target_folder)

for item in data_train:
    num = 0
    for i in item:
        file_name = f"{item[num]}_{item[1-num]}.mp4"
        source_file_path = os.path.join(source_folder, file_name)
        target_file_path = os.path.join(train_target_folder, file_name)
        if os.path.exists(source_file_path):
            shutil.copy(source_file_path, target_file_path)
        num = num + 1

if not os.path.exists(val_target_folder):
    os.makedirs(val_target_folder)

for item in data_val:
    num = 0
    for i in item:
        file_name = f"{item[num]}_{item[1-num]}.mp4"
        source_file_path = os.path.join(source_folder, file_name)
        target_file_path = os.path.join(val_target_folder, file_name)
        if os.path.exists(source_file_path):
            shutil.copy(source_file_path, target_file_path)
        num = num + 1

最后

接下来我会更新一个对视频提取帧的脚本操作,大家多多支持一下。

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值