대량의 사진 파일을 딥러닝 프로젝트에 사용하므로, GitHub에 직접 올리지 않고, 외부 저장소에 업로드한 후 코드로 연동

Google Drive 연동

  1. Google Drive에 사진 파일 업로드 (zip 압축파일로 만든 후 업로드)
  2. 업로드한 파일을 공유 가능 링크로 설정
  3. gdown 라이브러리 설치 및 사용
# gdown 설치
python -m pip install gdown
import gdown
import zipfile

def download_file(file_id, output):
    url = f'https://drive.google.com/uc?id={file_id}'
    print(f"Downloading {output}...")
    gdown.download(url, output, quiet=False)
    print(f"{output} downloaded.")

def extract_zip(file_name, extract_to):
    if os.path.exists(file_name):
        print(f"Extracting {file_name}...")
        with zipfile.ZipFile(file_name, 'r') as zip_ref:
            zip_ref.extractall(extract_to)
        print(f"{file_name} extracted to {extract_to}.")
    else:
        print(f"{file_name} not found.")

if __name__ == "__main__":
    #Google Drive 에서 가져온 파일 Id
    sit_file_id = '1QFqTjMe4Ti_WcY3Ez8q6laK1aQjJlNIE' # sit.zip 파일 ID
    other_file_id = '1-yr0u0e9xHFV6_tjWsi0yYlceyb8l3pa' # other.zip 파일 ID

# 데이터 폴더 생성 
os.makedirs('data', exist_ok=True)

# 파일 다운로드 
download_file(sit_file_id, 'dog_behavior_analysis/data/sit.zip')
download_file(other_file_id, 'dog_behavior_analysis/data/other.zip')

#압축 해제 경로 설정
os.makedirs('dog_behavior_analysis/data/sit', exist_ok=True)
os.makedirs('dog_behavior_analysis/data/other', exist_ok=True)

#압축해제
extract_zip('dog_behavior_analysis/data/sit.zip', 'dog_behavior_analysis/data')
extract_zip('dog_behavior_analysis/data/other.zip', 'dog_behavior_analysis/data')

# 데이터 경로 설정
sit_path = r'C:/Users/admin/IdeaProjects/TailsRoute_PJ/VScode/data'
other_path = r'C:/Users/admin/IdeaProjects/TailsRoute_PJ/VScode/data'
  1. README.md 파일에 사용자가 어떻게 데이터 다운로드 후 사용할지 설명글 적어두기

+ Recent posts