File size: 1,441 Bytes
51c8ed8
 
 
53af02c
51c8ed8
 
 
 
 
 
 
 
 
 
 
 
 
53af02c
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import os
from kaggle.api.kaggle_api_extended import KaggleApi
import shutil
import tarfile

data_dir = 'data/'
kaggle_api = KaggleApi()
kaggle_api.authenticate()
kaggle_api.dataset_download_files('gpiosenka/100-bird-species', path=data_dir, unzip=True)

# There is a bug in the dataset, where one of the folders is named "PARAKETT  AUKLET" instead of "PARAKETT AUKLET"
# We fix it by adding a space to the valid folder, because train and test are wrong and also the names in the labels file
# Fixing the path
fault_path = os.path.join(data_dir, 'valid', 'PARAKETT AUKLET')
correct_path = os.path.join(data_dir, 'valid', 'PARAKETT  AUKLET')
shutil.rmtree(correct_path, ignore_errors=True)
shutil.move(fault_path, correct_path)

# Compressing the train directory
with tarfile.open(os.path.join(data_dir, 'train.tar.gz'), 'w:gz') as tar:
    tar.add(os.path.join(data_dir, 'train'), arcname=os.path.basename(os.path.join(data_dir, 'train')))

# Compressing the test directory
with tarfile.open(os.path.join(data_dir, 'test.tar.gz'), 'w:gz') as tar:
    tar.add(os.path.join(data_dir, 'test'), arcname=os.path.basename(os.path.join(data_dir, 'test')))

# Compressing the valid directory
with tarfile.open(os.path.join(data_dir, 'valid.tar.gz'), 'w:gz') as tar:
    tar.add(os.path.join(data_dir, 'valid'), arcname=os.path.basename(os.path.join(data_dir, 'valid')))

os.remove(os.path.join(data_dir, 'EfficientNetB0-525-(224 X 224)- 98.97.h5'))