【CV基础】理解woodscape数据集

前言

最近需要用到鱼眼图像做语义分割、目标检测等任务,最开始先使用woodscape数据集进行训练、测试,故此记录学习woodscape数据集。

学习woodscape数据集

1. 随机划分数据集

shell脚本

#!/bin/sh
# 20240617: split woodscape dataset of 10 classes randomly based on  cityscape dataset format.
# * parent
# * .
# * ├── random_data
# * │   ├── gtFine
# * │   │   ├── train
# * │   │   │   └── major
# * │   │   └── val
# * │   │       └── minor
# * │   ├── leftImg8bit
# * │   │   ├── train
# * │   │   │   └── major
# * │   │   └── val
# * │   │       └── minor
# * │   └── rename_files.sh
# * ├── genpath.py

script_path="$(pwd)"
# randomdatapath="$script_path/randomdata"
# mkdir $randomdatapath
# cd $randomdatapath
cd $script_path
mkdir -p randomdata/gtFine/train/major
mkdir -p randomdata/gtFine/val/minor
mkdir -p randomdata/leftImg8bit/train/major
mkdir -p randomdata/leftImg8bit/val/minor
ls ../origdata/rgb_images/* > image.txt
python genpath.py

python脚本

'''
********************************************************************************
* @file  genpath.py
* @brief generate train/valid dataset from woodscape dataset.
********************************************************************************
* @author        xxx.zzz@yyy.com
* @date          2024.06.17
*
* @customer{     TBD}
* @project{      APA}
* @processor{    J3/TDA4}
* @copyright     (C) Copyright ABC Technologies Co., Ltd
*
*                Contents and presentations are protected world-wide.
*                Any kind of using, copying etc. is prohibited without proor permission.
*                All rights - incl. industrial property rights - are reserved.
*
* @starthistory
* @revision{     1.0.0, AMY, Initial version.}
* @endhistory
********************************************************************************
* parent
* .
* ├── random_data
* │   ├── gtFine
* │   │   ├── train
* │   │   │   └── major
* │   │   └── val
* │   │       └── minor
* │   ├── leftImg8bit
* │   │   ├── train
* │   │   │   └── major
* │   │   └── val
* │   │       └── minor
* │   └── rename_files.sh
* ├── genpath.py

********************************************************************************
'''
import os
import random
import shutil

def genpath(path):
    rgbpath = os.path.join(path, '../origdata/rgb_images')
    gtpath = os.path.join(path, '../origdata/semantic_annotations/semantic_annotations/gtLabels')

    f_image = open(os.path.join(path, 'image.txt'), 'rt').readlines()
    print(len(f_image))
    
    datapath = 'randomdata'
    image_train = os.path.join(path, datapath, 'leftImg8bit/train/major')
    image_valid = os.path.join(path, datapath, 'leftImg8bit/val/minor')
    label_train = os.path.join(path, datapath, 'gtFine/train/major')
    label_valid = os.path.join(path, datapath, 'gtFine/val/minor')
    
    n = len(f_image)
    i = 0
    val_percent = 0.2
    random.shuffle(f_image)
    nn = n*val_percent
    print(nn)
    for line in f_image:
        image_path = line.strip('\n')
        image_name = image_path.split('/')[-1]  
        # 
        old_imgpath = os.path.join(rgbpath, image_name)
        old_gtpath = os.path.join(gtpath, image_name)
        # 
        new_imgname = image_name.replace('.png', '_leftImg8bit.png')
        new_gtname  = image_name.replace('.png', '_gtFine_labelIds.png')

        if i<nn:
             # copy image
             new_imgpath = os.path.join(image_valid, new_imgname)
             shutil.copyfile(old_imgpath, new_imgpath) 
             # copy label
             new_gtpath = os.path.join(label_valid, new_gtname)
             shutil.copyfile(old_gtpath, new_gtpath) 
        else:
             # copy image
             new_imgpath = os.path.join(image_train, new_imgname)
             shutil.copyfile(old_imgpath, new_imgpath) 
             # copy label
             new_gtpath = os.path.join(label_train, new_gtname)
             shutil.copyfile(old_gtpath, new_gtpath) 
        i = i + 1
    f_image.close()

if __name__ == "__main__":
    path = os.path.dirname(os.path.realpath(__file__))
    genpath(path)
View Code

2. 

 

 

参考

posted on 2024-06-17 18:32  鹅要长大  阅读(16)  评论(0编辑  收藏  举报

导航