|
--- |
|
license: mit |
|
--- |
|
# Hướng Dẫn Chuẩn Bị Dữ Liệu |
|
|
|
## Tải và Giải Nén Dữ Liệu |
|
|
|
```python |
|
import requests |
|
import zipfile |
|
import os |
|
|
|
url = 'https://huggingface.co/datasets/Daominhwysi/VNonDB/resolve/main/vn_handwritten_images.zip?download=true' |
|
file_name = 'vn_handwritten_images.zip' |
|
|
|
response = requests.get(url, stream=True) |
|
|
|
if response.status_code == 200: |
|
with open(file_name, 'wb') as file: |
|
for chunk in response.iter_content(chunk_size=8192): |
|
file.write(chunk) |
|
print(f'Tải xuống thành công: {file_name}') |
|
else: |
|
print(f'Không thể tải xuống file. Mã lỗi: {response.status_code}') |
|
|
|
zip_file_path = '/content/vn_handwritten_images.zip' |
|
extract_to_dir = '/content/datasets' |
|
|
|
if not os.path.exists(extract_to_dir): |
|
os.makedirs(extract_to_dir) |
|
|
|
with zipfile.ZipFile(zip_file_path, 'r') as zip_ref: |
|
zip_ref.extractall(extract_to_dir) |
|
|
|
print(f'Giải nén thành công vào thư mục: {extract_to_dir}') |
|
``` |
|
|
|
## Đọc Dữ Liệu Nhãn |
|
|
|
### Đọc Dữ Liệu từ `labels.json` (CinamonAI) |
|
|
|
```python |
|
import json |
|
import pandas as pd |
|
import logging |
|
|
|
try: |
|
with opendatasets |
|
|
|
df = pd.concat([df_1, df_2], ignore_index=True) |
|
df.head() |
|
``` |