XiC1 commited on
Commit
d67c45e
1 Parent(s): 8cb9a5f

Upload folder using huggingface_hub

Browse files
convert2PNG.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ from PIL import Image
3
+ import json
4
+ import os
5
+
6
+
7
+ def process_images(image_filenames):
8
+ for image_filename in image_filenames:
9
+ prefix = os.path.splitext(image_filename)[0]
10
+
11
+ converted = False
12
+ if os.path.isfile(image_filename):
13
+ # 打开图片
14
+ try:
15
+ with Image.open(image_filename) as img:
16
+ if(img.format != 'PNG'):
17
+ img.save(f"{prefix}.png","PNG")
18
+ converted=True
19
+ print(f"convert {image_filename} to png")
20
+ except (IOError, SyntaxError) as e:
21
+ print(e)
22
+
23
+ if(converted): os.remove(image_filename)
24
+ else:
25
+ print(f"文件 {image_filename} 不存在。")
26
+
27
+
28
+ if __name__ == "__main__":
29
+ # 创建命令行解析器
30
+ parser = argparse.ArgumentParser(description='读取图片文件并输出为 JSON 格式')
31
+
32
+ # 添加位置参数,接受多个图片文件名
33
+ parser.add_argument('image_filenames', nargs='+', help='要处理的图片文件名')
34
+
35
+ # 解析命令行参数
36
+ args = parser.parse_args()
37
+
38
+ # 调用主函数
39
+ process_images(args.image_filenames)
data/test/bqb.tar CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:5f4d11e4f5671a4a006e4d79819157917bbf69ea6f4eadc501a11c27276df242
3
- size 137789440
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1aa0329f2f4e4389f1755f2e1ae94bfe053ad05f1a5cd8110e696818ce086b74
3
+ size 269557760
data/test/nailong.tar CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:dda336c6cc2272d7cc8085a5289f3de74b12c0cd34cd008442ebf602c7160649
3
- size 8386560
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef9e7c1396472eb1a8e79d4185d02a08c9250f83b57bdcae377e323b33800e31
3
+ size 56064000
data/train/bqb.tar CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:530d6d5bb4216430e466084ba035ee93f3c99c7cc84b43dc17c28460712f8f47
3
- size 1263370240
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ef87f29fa9454115b643629cae677d91641fdd9f864b601fd11705878637036
3
+ size 2380390400
data/train/nailong.tar CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:9c1268667dc31ea55588d79fcad01e1d7cf99098ca21418db9b5f4c4bac44819
3
- size 80035840
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2ff6b5ee7affa6d45a6519ac304ed6a895c665f0882cbbd4f1d3ce0b8aacfabe
3
+ size 390215680
generate_info.py CHANGED
@@ -6,6 +6,7 @@ import os
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
  # 检查文件是否存在
 
6
 
7
  def process_images(image_filenames, label):
8
  for image_filename in image_filenames:
9
+ prefix = os.path.splitext(image_filename)[0]
10
  json_filename = f"{os.path.splitext(image_filename)[0]}.json"
11
 
12
  # 检查文件是否存在
tar.sh CHANGED
@@ -8,10 +8,36 @@
8
  # @description : tar datas
9
  ######################################################################
10
 
11
- tar -cvf ./data/train/bqb.tar -C ./source/train/bqb .
12
- tar -cvf ./data/train/nailong.tar -C ./source/train/nailong .
13
- tar -cvf ./data/test/bqb.tar -C ./source/test/bqb .
14
- tar -cvf ./data/test/nailong.tar -C ./source/test/nailong .
 
15
 
 
 
 
 
 
 
 
 
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
 
8
  # @description : tar datas
9
  ######################################################################
10
 
11
+ index=(0 1 2 3)
12
+ splits=("train/bqb" "train/nailong" "test/bqb" "test/nailong")
13
+ lables=(0 1 0 1)
14
+ source_dir='source' # 源目录
15
+ data_dir='data' # data目录
16
 
17
+ rm -r $data_dir
18
+ #mkdir $data_dir
19
+ cp -r $source_dir $data_dir
20
+ # 遍历 splits 数组中的每个元素
21
+ for idx in "${index[@]}"; do
22
+ split=${splits[$idx]}
23
+ #cp -r "$source_dir/$split" "$data_dir/$splits"
24
+ folder="$data_dir/$split"
25
 
26
+ # 检查目录是否存在
27
+ if [ -d "$folder" ]; then
28
+ echo "找到文件夹: $(basename "$folder")"
29
+
30
+ lable=${lables[$idx]}
31
+
32
+
33
+ #echo $folder
34
+ python ./convert2PNG.py "$folder"/*
35
+
36
+ python ./generate_info.py "lable=${lables[$idx]}" "$folder"/*
37
+
38
+ tar -cvf "$data_dir/$split.tar" -C "$folder" . && rm -rf "$folder"
39
+ else
40
+ echo "目录 $folder 不存在,跳过。"
41
+ fi
42
+ done
43