icartoonface数据转为widerface格式数据集

数据说明

标注数据示例
# 55--Sports_Coach_Trainer/55_Sports_Coach_Trainer_sportcoaching_55_49.jpg
147 236 12 18 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 0.29
174 237 12 18 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 -1.0 0.37
204 233 14 21 205.009 240.054 1.0 208.357 238.982 1.0 204.875 243.804 1.0 206.08 248.357 1.0 207.821 247.018 1.0 0.34
针对WiderFace数据集中的人脸检测任务的标注,每一行代表一个人脸框的标注信息,具体含义如下:
  • 第一个数字是人脸框的左上角 x 坐标。
  • 第二个数字是人脸框的左上角 y 坐标。
  • 第三个数字是人脸框的宽度w。
  • 第四个数字是人脸框的高度h。
其他数字
  • 接下来的一系列数字是关于人脸框的一些属性信息,包括置信度和人脸关键点位置。在提供的示例中,有第三个人脸框有关键点信息。

  • 对于每个关键点,前两个数字是该关键点的 xy 坐标,然后是置信度(在这里的示例中是1.0),表示关键点的检测可信度。

  • 最后一个数字是人脸框的标签,表示人脸的遮挡程度,数值范围在0到1之间,0表示无遮挡,1表示完全遮挡。

  • 对于标注中出现的值为-1.0的情况,通常表示该项信息未提供或未检测到。在示例中,对于某些人脸框的关键点信息和遮挡程度都是-1.0,这表示在这些情况下,该人脸框的关键点位置或遮挡程度信息未被提供或未被检测到。

icartoonface数据转为widerface格式数据集

转换代码如下:
import pandas as pd
from io import StringIO
from tqdm import tqdm

# Define the function to convert CSV to WiderFace format with the user's specifications
def convert_csv_to_widerface_format_with_progress(csv_data_path, folder_name, mode='train'):
    # Read the CSV data from file path into a DataFrame
    if mode == 'train':
        df = pd.read_csv(csv_data_path, header=None, names=['image', 'x1', 'y1', 'x2', 'y2'])
    else:
        df = pd.read_csv(csv_data_path, header=None, names=['image', 'x1', 'y1', 'x2', 'y2', 'face'])

    # Calculate width and height
    df['width'] = df['x2'] - df['x1']
    df['height'] = df['y2'] - df['y1']
    if mode == 'train':
        df = pd.read_csv(csv_data_path, header=None, names=['image', 'x1', 'y1', 'x2', 'y2'])
    else:
        df = pd.read_csv(csv_data_path, header=None, names=['image', 'x1', 'y1', 'x2', 'y2', 'face'])

    # Calculate width and height
    df['width'] = df['x2'] - df['x1']
    df['height'] = df['y2'] - df['y1']

    # Define the landmark as -1 and occlusion as 1
    df['landmarks'] = " -1.0" * 15
    df['occlusion'] = 1.0

    # Update the image name to the specified format
    df['image'] = '# ' + folder_name + '/' + df['image']

    # Prepare the final DataFrame in WiderFace format
    widerface_df = df[['image', 'x1', 'y1', 'width', 'height', 'landmarks', 'occlusion']]

    # Initialize a progress bar
    tqdm.pandas(desc="Converting to WiderFace format")

    # Construct the annotations string without empty lines between annotations
    annotations = widerface_df.groupby('image').progress_apply(
        lambda x: '\n'.join(
            x[['x1', 'y1', 'width', 'height', 'landmarks', 'occlusion']].astype(str).agg(' '.join, axis=1))
    ).reset_index(name='annotations')

    # Combine the annotations with the image names
    final_annotations = annotations.apply(lambda x: x['image'] + '\n' + x['annotations'], axis=1)

    # Join all entries with newlines
    final_widerface_format = "\n".join(final_annotations)

    return final_widerface_format

# ----------------------------------------------------------------train data
# Example CSV data (the user will provide their own CSV data)
csv_data_path = '/home/cc/Downloads/py_projects/Pytorch_Retinaface/data/icartoonface_det_data/personai_icartoonface_dettrain/icartoonface_dettrain.csv'
# The folder name given by the user
folder_name = 'personai_icartoonface_dettrain'


# Convert to WiderFace format
widerface_formatted_data = convert_csv_to_widerface_format_with_progress(csv_data_path, folder_name)

# Save to a text file
output_file_with_folder_name = './personai_icartoonface_dettrain.txt'
with open(output_file_with_folder_name, 'w') as file:
    file.write(widerface_formatted_data)
print('数据转换完成...')
print('output:', output_file_with_folder_name)


# ----------------------------------------------------------------- test data
# Example CSV data (the user will provide their own CSV data)
csv_data_path = '/home/cc/Downloads/py_projects/Pytorch_Retinaface/data/icartoonface_det_data/personai_icartoonface_detval.csv'
# The folder name given by the user
folder_name = 'personai_icartoonface_detval'


# Convert to WiderFace format
widerface_formatted_data = convert_csv_to_widerface_format_with_progress(csv_data_path, folder_name, mode='val')

# Save to a text file
output_file_with_folder_name = './personai_icartoonface_detval.txt'
with open(output_file_with_folder_name, 'w') as file:
    file.write(widerface_formatted_data)
print('数据转换完成...')
print('output:', output_file_with_folder_name)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值