Upload folder using huggingface_hub
Browse files- .gitignore +1 -0
- data/test/bqb.tar +2 -2
- data/test/nailong.tar +2 -2
- data/train/bqb.tar +2 -2
- data/train/nailong.tar +2 -2
- generate_info.py +57 -0
- tar.sh +17 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
source/
|
data/test/bqb.tar
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5120d2471f9703eada3c0546fe631220047e0d4ef9086df0ce17fb1ce9f13164
|
3 |
+
size 137789440
|
data/test/nailong.tar
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0fd19e0e6e18e189d077849be3125f0222c75869d243238ebd5640db0e25ddb1
|
3 |
+
size 8386560
|
data/train/bqb.tar
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2d693f5c57923857f0b4ddaed2652c725673da8ed7fece422f1b477d066671a4
|
3 |
+
size 1263370240
|
data/train/nailong.tar
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e3fafcb22c764cabfce7f1ec6b262e2837f9320c87dfbe44b3fe226c506679b5
|
3 |
+
size 80035840
|
generate_info.py
ADDED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
from PIL import Image
|
3 |
+
import json
|
4 |
+
import os
|
5 |
+
|
6 |
+
|
7 |
+
def process_images(image_filenames, label):
|
8 |
+
for image_filename in image_filenames:
|
9 |
+
json_filename = f"{os.path.splitext(image_filename)[0]}.json"
|
10 |
+
|
11 |
+
# 检查文件是否存在
|
12 |
+
if os.path.isfile(image_filename):
|
13 |
+
# 打开图片
|
14 |
+
try:
|
15 |
+
with Image.open(image_filename) as img:
|
16 |
+
# 获取图片的基本信息
|
17 |
+
image_info = {
|
18 |
+
'filename': os.path.basename(image_filename),
|
19 |
+
'label': label,
|
20 |
+
'format': img.format,
|
21 |
+
'mode': img.mode,
|
22 |
+
'size': img.size,
|
23 |
+
# 'info': img.info
|
24 |
+
}
|
25 |
+
|
26 |
+
# 将信息输出为 JSON 格式
|
27 |
+
json_output = json.dumps(
|
28 |
+
image_info, ensure_ascii=False, indent=4)
|
29 |
+
|
30 |
+
# 打印 JSON 输出
|
31 |
+
# print(json_output)
|
32 |
+
|
33 |
+
# 将 JSON 输出写入文件
|
34 |
+
with open(json_filename, 'w', encoding='utf-8') as json_file:
|
35 |
+
print(f"write to {json_filename}")
|
36 |
+
json_file.write(json_output)
|
37 |
+
except (IOError, SyntaxError) as e:
|
38 |
+
print(e)
|
39 |
+
else:
|
40 |
+
print(f"文件 {image_filename} 不存在。")
|
41 |
+
|
42 |
+
|
43 |
+
if __name__ == "__main__":
|
44 |
+
# 创建命令行解析器
|
45 |
+
parser = argparse.ArgumentParser(description='读取图片文件并输出为 JSON 格式')
|
46 |
+
|
47 |
+
# 添加可选参数 --label
|
48 |
+
parser.add_argument('--label', type=int, default=None, help='图片的标签')
|
49 |
+
|
50 |
+
# 添加位置参数,接受多个图片文件名
|
51 |
+
parser.add_argument('image_filenames', nargs='+', help='要处理的图片文件名')
|
52 |
+
|
53 |
+
# 解析命令行参数
|
54 |
+
args = parser.parse_args()
|
55 |
+
|
56 |
+
# 调用主函数
|
57 |
+
process_images(args.image_filenames, args.label)
|
tar.sh
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env sh
|
2 |
+
|
3 |
+
######################################################################
|
4 |
+
# @author : xic (zeexoc@outlook.com)
|
5 |
+
# @file : tar
|
6 |
+
# @created : Saturday Nov 02, 2024 18:06:32 CST
|
7 |
+
#
|
8 |
+
# @description : tar datas
|
9 |
+
######################################################################
|
10 |
+
|
11 |
+
tar -cvf ./data/train/bqb.tar ./source/train/bqb
|
12 |
+
tar -cvf ./data/train/nailong.tar ./source/train/nailong
|
13 |
+
tar -cvf ./data/test/bqb.tar ./source/test/bqb
|
14 |
+
tar -cvf ./data/test/nailong.tar ./source/test/nailong
|
15 |
+
|
16 |
+
|
17 |
+
|