-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_data.py
55 lines (38 loc) · 1.41 KB
/
get_data.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import tensorflow as tf
from tensorflow.keras.applications.resnet import preprocess_input as resnet_preprocessing
from tensorflow.keras.layers import GlobalAveragePooling2D
from funcyou.dataset import download_kaggle_dataset
from pathlib import Path
from config import config
from zipfile import ZipFile
import os
import shutil
import glob
import json
dataset_url = Path('https://www.kaggle.com/datasets/hsankesara/flickr-image-dataset')
api_command = "kaggle datasets download -d hsankesara/flickr-image-dataset"
dest_caption_file_dir = config.raw_caption_file
src_caption_file_dir = Path("./flickr30k_images/flickr30k_images/results.csv")
def move_to_dest():
src_dir = "./flickr30k_images/flickr30k_images/flickr30k_images/"
dst_dir = config.image_dir
os.makedirs(dst_dir, exist_ok=True)
files = glob.glob(f"{src_dir}*")
for file in files:
filename = file.split("/")[-1]
dst_path = f"{dst_dir}/{filename}"
shutil.copy(file, dst_path)
shutil.copy(src_caption_file_dir, dest_caption_file_dir)
def download_dataset(path):
print("Downloading...")
download_kaggle_dataset(api_command, kaggle_json_filepath=path)
print("Downloaded.")
print('Extracting...')
with ZipFile('flickr-image-dataset.zip') as zip:
zip.extractall()
print('Moving...')
move_to_dest()
print('Done')
print('Cleaned.')
if __name__=='__main__':
print('hello ')