본문 바로가기
ML & DL/[CV] 나는 솔로 - 사이드프로젝트

Dataturks AccessDenied

by IT손흥민 2024. 4. 9.

목적

detectron2 실습을 하는 중간에 Dataturks에서 제공하는 Datasetaccess가 비활성화되어 접근을 할 수 없었다. 이에 비슷한 Dataset인 CelebFaces를 활용하여 내가 원하는 Format에 맞게 가공하여 작업하였다.
Dataturks를 dataset을 대신 진행한 방법에 대해 설명하고자 한다.

     


    오류 내용

    Data AccessDenied

    CelebFaces 사용 방법

    1. 파일 다운 받기

    https://mmlab.ie.cuhk.edu.hk/projects/CelebA.html

    1. 위의 주소로 접속 후 원본 데이터와 bbox 데이터를 다운받는다.

     

    CelebA Dataset

    Details CelebFaces Attributes Dataset (CelebA) is a large-scale face attributes dataset with more than 200K celebrity images, each with 40 attribute annotations. The images in this dataset cover large pose variations and background clutter. CelebA has larg

    mmlab.ie.cuhk.edu.hk

     

     

    2. 구글 드라이브로 이동 후, 현재 내 상황에 필요한 정보는 이미지와 Bounding box 정보만 다운로드하였다.
       다운로드한 목록 : 
       CelebA -> Anno 폴더 안의 'list_bbox_celeba.txt'
       CelebA -> Img 폴더 안의 'img_celeba.7z'
       총두 개를 다운로드하였다.

     

    3. img_celeba.7z 압축 풀기 위해 7 zip을 설치한다.
    * brew를 이용해 설치하였다.

    brew install p7zip

     

    4. 총 7개의 7z 파일을 한 곳에 저장한 뒤 압축을 푼다.

    7zr x img_celeba.7z.001


    2. 데이터 가공하기

     

    1. 'list_bbox_celeba.txt'의 데이터 확인

    import pandas as pd
    path = "사용자 폴더 경로"
    bbox = pd.read_table(f'{path}/list_bbox_celeba.txt', sep = '\s+', index_col='image_id')
    bbox

     

    2. width와 height는 bounding box의 길이를 나타낸다.
    각 좌표의 최댓값을 확인하기 위해 최솟값에 각각의 길이를 더하였다.

    x = []
    y = []
    
    for i in bbox.index:
        x_1 = bbox.loc[i]['x_1']
        y_1 = bbox.loc[i]['y_1']
        width = bbox.loc[i]['width']
        height = bbox.loc[i]['height']
        x.append(x_1+width)
        y.append(y_1+height)
    bbox['x_2'] = x
    bbox['y_2'] = y
    bbox_second = bbox

     

    3. 필요 없는 열은 삭제하였다.

    bbox_second.drop(['width','height'], axis=1, inplace=True)

     

    4. 현재 라벨 확인이 어려운 관계로 'Face'로 임의 지정하였다.

    bbox_second['label'] = "Face"
    bbox_second

     

     

    5. 이미지 width와 height 길이를 추가하고자 한다.

    from PIL import Image
    path = "사용자 폴더 경로"
    width_list = []
    height_list = []
    for i in bbox_second.index:
        im = Image.open(f'{path}/{i}')
        width, height = im.size
        width_list.append(width)
        height_list.append(height)
    bbox_second['width'] = width_list
    bbox_second['height'] = height_list

     

     

    6. 칼럼명 변경하기

     

    7. 인덱스 리셋 후 저장하기

    bbox_second['file_name'] = bbox_second.index
    bbox_second.reset_index(drop=True)
    bbox_second.to_csv('annotations.csv', header=True, index=None)


     

    마무리

    데이터 셋 가공은 어렵지 않게 진행되었다.
    bounding box 테스트 결과도 오류 없이 진행되는 걸 확인할 수 있었다. 앞으로 처리할 모델링 작업이 기대된다.

     

    댓글