Update fiftyone.py
Browse files- fiftyone.py +39 -39
fiftyone.py
CHANGED
@@ -1,53 +1,53 @@
|
|
1 |
-
import fiftyone as fo
|
2 |
-
import datasets
|
3 |
-
import os
|
4 |
-
import PIL
|
5 |
|
6 |
|
7 |
-
def _get_extension(image):
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
|
15 |
|
16 |
-
def _get_download_dir():
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
|
25 |
|
26 |
|
27 |
-
def convert_to_fiftyone(hf_dataset):
|
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 |
-
|
|
|
1 |
+
# import fiftyone as fo
|
2 |
+
# import datasets
|
3 |
+
# import os
|
4 |
+
# import PIL
|
5 |
|
6 |
|
7 |
+
# def _get_extension(image):
|
8 |
+
# if isinstance(image, PIL.PngImagePlugin.PngImageFile):
|
9 |
+
# return ".png"
|
10 |
+
# elif isinstance(image, PIL.JpegImagePlugin.JpegImageFile):
|
11 |
+
# return ".jpg"
|
12 |
+
# else:
|
13 |
+
# return "web"
|
14 |
|
15 |
|
16 |
+
# def _get_download_dir():
|
17 |
+
# download_dir = os.path.join(
|
18 |
+
# fo.config.default_dataset_dir, "huggingface", "hub", "jamarks/pokemon_copy"
|
19 |
+
# )
|
20 |
|
21 |
+
# if not os.path.exists(download_dir):
|
22 |
+
# os.makedirs(download_dir)
|
23 |
|
24 |
+
# return download_dir
|
25 |
|
26 |
|
27 |
+
# def convert_to_fiftyone(hf_dataset):
|
28 |
+
# dataset = fo.Dataset(name="pokemon-blip-captions", persistent=True, overwrite=True)
|
29 |
|
30 |
+
# splits = ["train"]
|
31 |
+
# download_dir = _get_download_dir()
|
32 |
|
33 |
+
# for split in splits:
|
34 |
+
# samples = []
|
35 |
+
# for i, item in enumerate(hf_dataset[split]):
|
36 |
+
# img = item["image"]
|
37 |
+
# ext = _get_extension(img)
|
38 |
+
# fp = os.path.join(download_dir, f"{split}_{i}{ext}")
|
39 |
+
# if not os.path.exists(fp):
|
40 |
+
# img.save(fp)
|
41 |
|
42 |
+
# sample_dict = {
|
43 |
+
# "filepath": fp,
|
44 |
+
# "tags": [split],
|
45 |
+
# "text": item["text"],
|
46 |
+
# }
|
47 |
|
48 |
+
# sample = fo.Sample(**sample_dict)
|
49 |
+
# samples.append(sample)
|
50 |
|
51 |
+
# dataset.add_samples(samples)
|
52 |
|
53 |
+
# return dataset
|