Daominhwysi commited on
Commit
f6dac3e
1 Parent(s): beba16d

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +116 -3
README.md CHANGED
@@ -1,3 +1,116 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+ # Hướng Dẫn Chuẩn Bị Dữ Liệu
5
+
6
+ ## Tải và Giải Nén Dữ Liệu
7
+
8
+ ```python
9
+ import requests
10
+ import zipfile
11
+ import os
12
+
13
+ url = 'https://huggingface.co/datasets/Daominhwysi/VNonDB/resolve/main/vn_handwritten_images.zip?download=true'
14
+ file_name = 'vn_handwritten_images.zip'
15
+
16
+ response = requests.get(url, stream=True)
17
+
18
+ if response.status_code == 200:
19
+ with open(file_name, 'wb') as file:
20
+ for chunk in response.iter_content(chunk_size=8192):
21
+ file.write(chunk)
22
+ print(f'Tải xuống thành công: {file_name}')
23
+ else:
24
+ print(f'Không thể tải xuống file. Mã lỗi: {response.status_code}')
25
+
26
+ zip_file_path = '/content/vn_handwritten_images.zip'
27
+ extract_to_dir = '/content/datasets'
28
+
29
+ if not os.path.exists(extract_to_dir):
30
+ os.makedirs(extract_to_dir)
31
+
32
+ with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
33
+ zip_ref.extractall(extract_to_dir)
34
+
35
+ print(f'Giải nén thành công vào thư mục: {extract_to_dir}')
36
+ ```
37
+
38
+ ## Đọc Dữ Liệu Nhãn
39
+
40
+ ### Đọc Dữ Liệu từ `labels.json` (CinamonAI)
41
+
42
+ ```python
43
+ import json
44
+ import pandas as pd
45
+ import logging
46
+
47
+ try:
48
+ with open('/content/datasets/cinamonai/labels.json', 'r') as file:
49
+ labels = json.load(file)
50
+ df_1 = pd.DataFrame(list(labels.items()), columns=['file_name', 'label'])
51
+ except Exception as e:
52
+ logging.error(f"Lỗi khi tải nhãn: {e}")
53
+
54
+ df_1['file_name'] = df_1['file_name'].apply(lambda x: f'/content/datasets/cinamonai/data/{x}.jpeg')
55
+
56
+ df_1.head()
57
+ ```
58
+
59
+ ### Đọc Dữ Liệu từ `labels.json` (VNonDB)
60
+
61
+ ```python
62
+ import json
63
+ import pandas as pd
64
+ import logging
65
+
66
+ try:
67
+ with open('/content/datasets/vnondb/labels.json', 'r') as file:
68
+ labels = json.load(file)
69
+ df_2 = pd.DataFrame(list(labels.items()), columns=['file_name', 'label'])
70
+ except Exception as e:
71
+ logging.error(f"Lỗi khi tải nhãn: {e}")
72
+
73
+ df_2['file_name'] = df_2['file_name'].apply(lambda x: f'/content/datasets/vnondb/outputs_image/{x}.jpeg')
74
+
75
+ df_2.head()
76
+ ```
77
+
78
+ ## Hiển Thị Ảnh và Nhãn
79
+
80
+ ### Hiển Thị Ảnh từ `df_1`
81
+
82
+ ```python
83
+ import pandas as pd
84
+ import random
85
+ from PIL import Image
86
+ import matplotlib.pyplot as plt
87
+
88
+ random_row = df_1.sample(n=1).iloc[0]
89
+ file_path = random_row['file_name']
90
+ image = Image.open(file_path).convert('RGB')
91
+ plt.figure(figsize=(20, 10))
92
+ plt.imshow(image)
93
+ plt.axis('off')
94
+ plt.show()
95
+
96
+ print(f"Labeled as: {random_row['label']}")
97
+ ```
98
+
99
+ ### Hiển Thị Ảnh từ `df_2`
100
+
101
+ ```python
102
+ import pandas as pd
103
+ import random
104
+ from PIL import Image
105
+ import matplotlib.pyplot as plt
106
+
107
+ random_row = df_2.sample(n=1).iloc[0]
108
+ file_path = random_row['file_name']
109
+ image = Image.open(file_path).convert('RGB')
110
+ plt.figure(figsize=(20, 10))
111
+ plt.imshow(image)
112
+ plt.axis('off')
113
+ plt.show()
114
+
115
+ print(f"Labeled as: {random_row['label']}")
116
+ ```