vpippi commited on
Commit
e265d63
·
verified ·
1 Parent(s): ea49f11

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +148 -139
README.md CHANGED
@@ -1,140 +1,149 @@
1
- ---
2
- license: mit
3
- ---
4
-
5
- # Accessing the `font-square-v2` Dataset on Hugging Face
6
-
7
- The `font-square-v2` dataset is hosted on Hugging Face at [blowing-up-groundhogs/font-square-v2](https://huggingface.co/datasets/blowing-up-groundhogs/font-square-v2). The dataset is stored in WebDataset format, with all tar files located in the `tars/` folder of the repository. Each tar file contains multiple samples; each sample includes:
8
- - An RGB image file (with the extension `.rgb.png`)
9
- - A black-and-white image file (with the extension `.bw.png`)
10
- - A JSON file (`.json`) with metadata (e.g. text and writer ID)
11
-
12
- You can access the dataset in one of two ways: by downloading it locally or by streaming it directly over HTTP.
13
-
14
- ---
15
-
16
- ## 1. Downloading the Dataset Locally
17
-
18
- You can download the dataset locally using either Git LFS or the [huggingface_hub](https://huggingface.co/docs/huggingface_hub) Python library.
19
-
20
- ### **Using Git LFS**
21
-
22
- Clone the repository (make sure [Git LFS](https://git-lfs.github.com/) is installed):
23
-
24
- ```bash
25
- git lfs clone https://huggingface.co/datasets/blowing-up-groundhogs/font-square-v2
26
- ```
27
-
28
- This will create a local directory named `font-square-v2` that contains the `tars/` folder with all the tar shards.
29
-
30
- ### **Using the huggingface_hub Python Library**
31
-
32
- Alternatively, you can download a snapshot of the dataset in your Python code:
33
-
34
- ```python
35
- from huggingface_hub import snapshot_download
36
-
37
- # Download the repository; the local path is returned
38
- local_dir = snapshot_download(repo_id="blowing-up-groundhogs/font-square-v2", repo_type="dataset")
39
- print("Dataset downloaded to:", local_dir)
40
- ```
41
-
42
- After downloading, the tar shards are available in the `tars/` subdirectory of `local_dir`.
43
-
44
- ### **Using WebDataset with the Local Files**
45
-
46
- Once the dataset is downloaded locally, you can load it with [WebDataset](https://github.com/webdataset/webdataset). For example:
47
-
48
- ```python
49
- import webdataset as wds
50
- import os
51
- from pathlib import Path
52
-
53
- # Assuming the dataset was downloaded to `local_dir` and tar shards are in the 'tars' folder
54
- local_dir = "path/to/font-square-v2" # Update this path if necessary
55
- tar_pattern = os.path.join(local_dir, "tars", "{000000..000499}.tar") # Adjust range to match your tar shard naming
56
-
57
- # Create a WebDataset
58
- dataset = wds.WebDataset(tar_pattern).decode("pil")
59
-
60
- # Example: Iterate over a few samples
61
- for sample in dataset:
62
- # Access sample items
63
- rgb_image = sample["rgb.png"] # RGB image (PIL image)
64
- bw_image = sample["bw.png"] # BW image (PIL image)
65
- metadata = sample["json"]
66
-
67
- print("Sample metadata:", metadata)
68
-
69
- # Process the images as needed...
70
- break
71
- ```
72
-
73
- ---
74
-
75
- ## 2. Streaming the Dataset Directly Over HTTP
76
-
77
- If you prefer to stream the dataset directly from Hugging Face (without downloading the entire dataset), you can use the HTTP URLs provided by the Hugging Face CDN. Make sure that your tar files are public and accessible.
78
-
79
- For example, if the tar shards are available at:
80
-
81
- ```
82
- https://huggingface.co/datasets/blowing-up-groundhogs/font-square-v2/resolve/main/tars/000000.tar
83
- https://huggingface.co/datasets/blowing-up-groundhogs/font-square-v2/resolve/main/tars/000001.tar
84
- ...
85
- ```
86
-
87
- you can set up your WebDataset as follows:
88
-
89
- ```python
90
- import webdataset as wds
91
-
92
- # Define the URL pattern to stream the tar shards directly from Hugging Face
93
- url_pattern = "https://huggingface.co/datasets/blowing-up-groundhogs/font-square-v2/resolve/main/tars/{000000..000499}.tar"
94
- # Adjust the shard range (here 000000 to 000010) to cover all your tar shards.
95
-
96
- # Create a WebDataset that streams data
97
- dataset = wds.WebDataset(url_pattern).decode("pil")
98
-
99
- # Iterate over a few samples from the streamed dataset
100
- for sample in dataset:
101
- rgb_image = sample["rgb.png"]
102
- bw_image = sample["bw.png"]
103
- metadata = sample["json"]
104
-
105
- print("Sample metadata:", metadata)
106
-
107
- # Process sample as needed...
108
- break
109
- ```
110
-
111
- **Note:** Streaming performance depends on your network connection and the Hugging Face CDN. If you experience any slowdowns, consider downloading the dataset locally instead.
112
-
113
- ---
114
-
115
- ## Additional Considerations
116
-
117
- - **Decoding:**
118
- The `.decode("pil")` method in the WebDataset pipeline converts image bytes into PIL images. If you prefer PyTorch tensors, you can add a transformation:
119
-
120
- ```python
121
- import torchvision.transforms as transforms
122
- transform = transforms.ToTensor()
123
-
124
- dataset = (
125
- wds.WebDataset(url_pattern)
126
- .decode("pil")
127
- .map(lambda sample: {
128
- "rgb": transform(sample["rgb.png"]),
129
- "bw": transform(sample["bw.png"]),
130
- "metadata": sample["json"],
131
- })
132
- )
133
- ```
134
-
135
- - **Shard Naming:**
136
- Ensure that the naming convention in your `tars/` folder matches the URL pattern used above. Adjust the pattern `{000000..000499}` accordingly if your tar files have a different naming scheme or if there are more shards.
137
-
138
- ---
139
-
 
 
 
 
 
 
 
 
 
140
  By following these instructions, you can easily load and work with the `font-square-v2` dataset from Hugging Face in your Python projects using WebDataset.
 
1
+ ---
2
+ license: mit
3
+ configs:
4
+ - config_name: default
5
+ data_files:
6
+ - split: train
7
+ path: tars/train/*.tar
8
+ - split: fine_tune
9
+ path: tars/train/*.tar
10
+ language:
11
+ - en
12
+ ---
13
+
14
+ # Accessing the `font-square-v2` Dataset on Hugging Face
15
+
16
+ The `font-square-v2` dataset is hosted on Hugging Face at [blowing-up-groundhogs/font-square-v2](https://huggingface.co/datasets/blowing-up-groundhogs/font-square-v2). The dataset is stored in WebDataset format, with all tar files located in the `tars/` folder of the repository. Each tar file contains multiple samples; each sample includes:
17
+ - An RGB image file (with the extension `.rgb.png`)
18
+ - A black-and-white image file (with the extension `.bw.png`)
19
+ - A JSON file (`.json`) with metadata (e.g. text and writer ID)
20
+
21
+ You can access the dataset in one of two ways: by downloading it locally or by streaming it directly over HTTP.
22
+
23
+ ---
24
+
25
+ ## 1. Downloading the Dataset Locally
26
+
27
+ You can download the dataset locally using either Git LFS or the [huggingface_hub](https://huggingface.co/docs/huggingface_hub) Python library.
28
+
29
+ ### **Using Git LFS**
30
+
31
+ Clone the repository (make sure [Git LFS](https://git-lfs.github.com/) is installed):
32
+
33
+ ```bash
34
+ git lfs clone https://huggingface.co/datasets/blowing-up-groundhogs/font-square-v2
35
+ ```
36
+
37
+ This will create a local directory named `font-square-v2` that contains the `tars/` folder with all the tar shards.
38
+
39
+ ### **Using the huggingface_hub Python Library**
40
+
41
+ Alternatively, you can download a snapshot of the dataset in your Python code:
42
+
43
+ ```python
44
+ from huggingface_hub import snapshot_download
45
+
46
+ # Download the repository; the local path is returned
47
+ local_dir = snapshot_download(repo_id="blowing-up-groundhogs/font-square-v2", repo_type="dataset")
48
+ print("Dataset downloaded to:", local_dir)
49
+ ```
50
+
51
+ After downloading, the tar shards are available in the `tars/` subdirectory of `local_dir`.
52
+
53
+ ### **Using WebDataset with the Local Files**
54
+
55
+ Once the dataset is downloaded locally, you can load it with [WebDataset](https://github.com/webdataset/webdataset). For example:
56
+
57
+ ```python
58
+ import webdataset as wds
59
+ import os
60
+ from pathlib import Path
61
+
62
+ # Assuming the dataset was downloaded to `local_dir` and tar shards are in the 'tars' folder
63
+ local_dir = "path/to/font-square-v2" # Update this path if necessary
64
+ tar_pattern = os.path.join(local_dir, "tars", "{000000..000499}.tar") # Adjust range to match your tar shard naming
65
+
66
+ # Create a WebDataset
67
+ dataset = wds.WebDataset(tar_pattern).decode("pil")
68
+
69
+ # Example: Iterate over a few samples
70
+ for sample in dataset:
71
+ # Access sample items
72
+ rgb_image = sample["rgb.png"] # RGB image (PIL image)
73
+ bw_image = sample["bw.png"] # BW image (PIL image)
74
+ metadata = sample["json"]
75
+
76
+ print("Sample metadata:", metadata)
77
+
78
+ # Process the images as needed...
79
+ break
80
+ ```
81
+
82
+ ---
83
+
84
+ ## 2. Streaming the Dataset Directly Over HTTP
85
+
86
+ If you prefer to stream the dataset directly from Hugging Face (without downloading the entire dataset), you can use the HTTP URLs provided by the Hugging Face CDN. Make sure that your tar files are public and accessible.
87
+
88
+ For example, if the tar shards are available at:
89
+
90
+ ```
91
+ https://huggingface.co/datasets/blowing-up-groundhogs/font-square-v2/resolve/main/tars/000000.tar
92
+ https://huggingface.co/datasets/blowing-up-groundhogs/font-square-v2/resolve/main/tars/000001.tar
93
+ ...
94
+ ```
95
+
96
+ you can set up your WebDataset as follows:
97
+
98
+ ```python
99
+ import webdataset as wds
100
+
101
+ # Define the URL pattern to stream the tar shards directly from Hugging Face
102
+ url_pattern = "https://huggingface.co/datasets/blowing-up-groundhogs/font-square-v2/resolve/main/tars/{000000..000499}.tar"
103
+ # Adjust the shard range (here 000000 to 000010) to cover all your tar shards.
104
+
105
+ # Create a WebDataset that streams data
106
+ dataset = wds.WebDataset(url_pattern).decode("pil")
107
+
108
+ # Iterate over a few samples from the streamed dataset
109
+ for sample in dataset:
110
+ rgb_image = sample["rgb.png"]
111
+ bw_image = sample["bw.png"]
112
+ metadata = sample["json"]
113
+
114
+ print("Sample metadata:", metadata)
115
+
116
+ # Process sample as needed...
117
+ break
118
+ ```
119
+
120
+ **Note:** Streaming performance depends on your network connection and the Hugging Face CDN. If you experience any slowdowns, consider downloading the dataset locally instead.
121
+
122
+ ---
123
+
124
+ ## Additional Considerations
125
+
126
+ - **Decoding:**
127
+ The `.decode("pil")` method in the WebDataset pipeline converts image bytes into PIL images. If you prefer PyTorch tensors, you can add a transformation:
128
+
129
+ ```python
130
+ import torchvision.transforms as transforms
131
+ transform = transforms.ToTensor()
132
+
133
+ dataset = (
134
+ wds.WebDataset(url_pattern)
135
+ .decode("pil")
136
+ .map(lambda sample: {
137
+ "rgb": transform(sample["rgb.png"]),
138
+ "bw": transform(sample["bw.png"]),
139
+ "metadata": sample["json"],
140
+ })
141
+ )
142
+ ```
143
+
144
+ - **Shard Naming:**
145
+ Ensure that the naming convention in your `tars/` folder matches the URL pattern used above. Adjust the pattern `{000000..000499}` accordingly if your tar files have a different naming scheme or if there are more shards.
146
+
147
+ ---
148
+
149
  By following these instructions, you can easily load and work with the `font-square-v2` dataset from Hugging Face in your Python projects using WebDataset.