JianShangQuan commited on
Commit
81be0e4
·
verified ·
1 Parent(s): 6edf7e4

Upload folder using huggingface_hub

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .DS_Store +0 -0
  2. data_splitting.py +89 -0
  3. test/Apple/Apple (1133).jpeg +3 -0
  4. test/Apple/Apple (1153).jpeg +3 -0
  5. test/Apple/Apple (12).png +3 -0
  6. test/Apple/Apple (1348).jpeg +3 -0
  7. test/Apple/Apple (1413).jpeg +3 -0
  8. test/Apple/Apple (1415).jpeg +3 -0
  9. test/Apple/Apple (1423).jpeg +3 -0
  10. test/Apple/Apple (1526).jpeg +3 -0
  11. test/Apple/Apple (1555).jpeg +3 -0
  12. test/Apple/Apple (1624).jpeg +3 -0
  13. test/Apple/Apple (1729).jpeg +3 -0
  14. test/Apple/Apple (1750).jpeg +3 -0
  15. test/Apple/Apple (1789).jpeg +3 -0
  16. test/Apple/Apple (1809).jpeg +3 -0
  17. test/Apple/Apple (1976).jpeg +3 -0
  18. test/Apple/Apple (233).jpeg +3 -0
  19. test/Apple/Apple (27).jpeg +3 -0
  20. test/Apple/Apple (28).jpeg +3 -0
  21. test/Apple/Apple (420).jpeg +3 -0
  22. test/Apple/Apple (545).jpeg +3 -0
  23. test/Banana/Banana (2044).jpeg +3 -0
  24. test/Banana/Banana (2067).jpeg +3 -0
  25. test/Banana/Banana (2120).jpeg +3 -0
  26. test/Banana/Banana (2121).jpeg +3 -0
  27. test/Banana/Banana (2179).jpeg +3 -0
  28. test/Banana/Banana (2279).jpeg +3 -0
  29. test/Banana/Banana (2291).jpeg +3 -0
  30. test/Banana/Banana (2448).jpeg +3 -0
  31. test/Banana/Banana (2580).jpeg +3 -0
  32. test/Banana/Banana (2712).jpeg +3 -0
  33. test/Banana/Banana (2727).jpeg +3 -0
  34. test/Banana/Banana (2845).jpeg +3 -0
  35. test/Banana/Banana (2928).jpeg +3 -0
  36. test/Banana/Banana (3362).jpeg +3 -0
  37. test/Banana/Banana (3449).jpeg +3 -0
  38. test/Banana/Banana (3597).jpeg +3 -0
  39. test/Banana/Banana (3652).jpeg +3 -0
  40. test/Banana/Banana (3813).jpeg +3 -0
  41. test/Banana/Banana (3901).jpeg +3 -0
  42. test/Banana/Banana (3939).jpeg +3 -0
  43. test/Grape/Grape (1073).jpeg +3 -0
  44. test/Grape/Grape (1090).jpeg +3 -0
  45. test/Grape/Grape (1222).jpeg +3 -0
  46. test/Grape/Grape (1266).jpeg +3 -0
  47. test/Grape/Grape (1335).jpeg +3 -0
  48. test/Grape/Grape (1470).jpeg +3 -0
  49. test/Grape/Grape (1521).jpeg +3 -0
  50. test/Grape/Grape (1575).jpeg +3 -0
.DS_Store ADDED
Binary file (6.15 kB). View file
 
data_splitting.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ '''
2
+
3
+ This code is a data preprocessing script that is used for creating a dataset to train, validate and test an image classification model. Specifically, it creates a dataset of fruit images, including Apples, Bananas, Grapes, Mangos, and Strawberries.
4
+
5
+ The script first defines the class names and number of images per class by counting the number of files in the directory for each fruit. It then creates three directories, one for each dataset split, i.e., training, validation, and testing. These directories are created if they don't exist.
6
+
7
+ The script then creates subdirectories in each of the three main directories for each fruit class. This step creates a hierarchical structure for the dataset, where each fruit class has a folder in each dataset split directory.
8
+
9
+ Next, the script collects all the image paths for each fruit class, storing them in a list. It then shuffles the paths randomly to ensure that the data is not biased in any way.
10
+
11
+ The script then calculates the size of each dataset split based on the total number of images and predefined ratios. The training dataset is the largest, comprising 97% of the total data, while the validation and testing datasets comprise 2% and 1%, respectively.
12
+
13
+ The script then creates three separate lists, one for each dataset split, containing tuples with the old and new paths for each image. The new paths are generated by concatenating the class folder, the image filename, and the corresponding dataset split directory.
14
+
15
+ Finally, the script moves each image from its old path to its new path in the appropriate dataset split directory using the os.rename() function. It then removes the old directories for each fruit class, as they are no longer needed.
16
+
17
+ The script outputs the total size of the data, as well as the size of each dataset split. Once the script finishes running, the dataset is ready to use for training, validating, and testing an image classification model.
18
+
19
+ '''
20
+
21
+
22
+ import os
23
+ import numpy as np
24
+ from glob import glob
25
+ from tqdm import tqdm
26
+
27
+ # Define class names and number of images per class
28
+ class_names = ['Apple', 'Banana', 'Grape', 'Mango', 'Strawberry']
29
+ n_images_per_class = len(os.listdir(f"./{class_names[0]}"))
30
+
31
+ # Define train, valid, and test directories and create them if they don't exist
32
+ train_dir = "./train"
33
+ valid_dir = "./valid"
34
+ test_dir = "./test"
35
+
36
+ for directory in [train_dir, valid_dir, test_dir]:
37
+ if not os.path.exists(directory):
38
+ os.makedirs(directory)
39
+
40
+ # Create subdirectories for each class in train, valid, and test directories
41
+ for name in class_names:
42
+ for directory in [train_dir, valid_dir, test_dir]:
43
+ class_path = os.path.join(directory, name)
44
+ if not os.path.exists(class_path):
45
+ os.makedirs(class_path)
46
+
47
+ # Collect all image paths for each class
48
+ all_class_paths = [glob(f"./{name}/*") for name in class_names]
49
+
50
+ # Define training, validation, and testing size
51
+ total_size = sum([len(paths) for paths in all_class_paths])
52
+
53
+ train_ratio = 0.97
54
+ valid_ratio = 0.02
55
+ test_ratio = 0.01
56
+
57
+ train_size = int(total_size * train_ratio)
58
+ valid_size = int(total_size * valid_ratio)
59
+ test_size = int(total_size * test_ratio)
60
+
61
+ train_images_per_class = int(n_images_per_class * train_ratio)
62
+ valid_images_per_class = int(n_images_per_class * valid_ratio)
63
+ test_images_per_class = int(n_images_per_class * test_ratio)
64
+
65
+ print("Total Data Size : {}".format(total_size))
66
+ print("Training Size : {}".format(train_size))
67
+ print("Validation Size : {}".format(valid_size))
68
+ print("Testing Size : {}\n".format(test_size))
69
+
70
+ # Shuffle image paths for each class
71
+ for paths in all_class_paths:
72
+ np.random.shuffle(paths)
73
+
74
+ # Define lists of (old_path, new_path) tuples for training, validation, and testing images
75
+ train_images = [(path, os.path.join(train_dir, path.split('/')[-2], path.split('/')[-1])) for paths in all_class_paths for path in paths[:train_images_per_class]]
76
+ valid_images = [(path, os.path.join(valid_dir, path.split('/')[-2], path.split('/')[-1])) for paths in all_class_paths for path in paths[train_images_per_class: train_images_per_class + valid_images_per_class]]
77
+ test_images = [(path, os.path.join(test_dir, path.split('/')[-2], path.split('/')[-1])) for paths in all_class_paths for path in paths[train_images_per_class+valid_images_per_class: train_images_per_class + valid_images_per_class + test_images_per_class]]
78
+
79
+ # Move images to their new directories
80
+ for images, data_type in [(train_images, "Training"), (valid_images, "Validation"), (test_images, "Testing")]:
81
+ for (old_path, new_path) in tqdm(images, desc=data_type + " Data"):
82
+ os.rename(old_path, new_path)
83
+
84
+ # Remove the old directories
85
+ for directory in class_names:
86
+ os.rmdir("./" + directory)
87
+
88
+ # Print confirmation message
89
+ print("ALL DONE!!")
test/Apple/Apple (1133).jpeg ADDED

Git LFS Details

  • SHA256: 7e0e9935b0d9c2cd714aaa03cf779fde15f8c16b67d0743f68c386784ab2a595
  • Pointer size: 129 Bytes
  • Size of remote file: 5.09 kB
test/Apple/Apple (1153).jpeg ADDED

Git LFS Details

  • SHA256: 445f789d84cb433f7dd88dc6173f5ce553a649723f957b1c17c36eb17d42695e
  • Pointer size: 129 Bytes
  • Size of remote file: 4.34 kB
test/Apple/Apple (12).png ADDED

Git LFS Details

  • SHA256: a0f4b62c9a59963518516286b573355264a0f1f6f4e169f5f8012ee6933f99d6
  • Pointer size: 129 Bytes
  • Size of remote file: 8.07 kB
test/Apple/Apple (1348).jpeg ADDED

Git LFS Details

  • SHA256: fcc2f9ccb29ed8fae5411dd388d2c7bba8ee6e64d11ea9a0d573df77a0a49207
  • Pointer size: 129 Bytes
  • Size of remote file: 4.92 kB
test/Apple/Apple (1413).jpeg ADDED

Git LFS Details

  • SHA256: bd834868f813c0713d1f24a5957c98e9a4b3dcd53b5cdfe7b0098a7587fb8747
  • Pointer size: 129 Bytes
  • Size of remote file: 5.52 kB
test/Apple/Apple (1415).jpeg ADDED

Git LFS Details

  • SHA256: 757b6c6e424d033a06388d6d1fb5b6005cc069137a557013d8e34c081ac454c8
  • Pointer size: 130 Bytes
  • Size of remote file: 11.5 kB
test/Apple/Apple (1423).jpeg ADDED

Git LFS Details

  • SHA256: d7a789db5aa653e1de6e364ed5fe6caf05418c012d4b7f78841c08e6a533e1fc
  • Pointer size: 129 Bytes
  • Size of remote file: 5.35 kB
test/Apple/Apple (1526).jpeg ADDED

Git LFS Details

  • SHA256: 9bf3fc1d7172a6d1b6047b2a841653e3bb75acd1007c77b2505e1eb86ec09235
  • Pointer size: 129 Bytes
  • Size of remote file: 4.48 kB
test/Apple/Apple (1555).jpeg ADDED

Git LFS Details

  • SHA256: 39884070fd14e4102127b22b208e905262a2d4d3d13bfa3bb4313f8a91a42e2c
  • Pointer size: 129 Bytes
  • Size of remote file: 9.51 kB
test/Apple/Apple (1624).jpeg ADDED

Git LFS Details

  • SHA256: e4b9595aa684f3e28b4e99c63241b6612c166d7d882b07f9b61ee78825527b08
  • Pointer size: 129 Bytes
  • Size of remote file: 9.4 kB
test/Apple/Apple (1729).jpeg ADDED

Git LFS Details

  • SHA256: 7d533b55b78253722f8970c8bd1d9d269e465d82a52f4b483fee55945b34c0bf
  • Pointer size: 130 Bytes
  • Size of remote file: 11.9 kB
test/Apple/Apple (1750).jpeg ADDED

Git LFS Details

  • SHA256: 8dbd68b06839e682f2053f788f59e1957ff9c2746372f3be7dfa50872e025eff
  • Pointer size: 129 Bytes
  • Size of remote file: 4.09 kB
test/Apple/Apple (1789).jpeg ADDED

Git LFS Details

  • SHA256: 0b03317b677017b88998be699a890a1bb58d5d4ba5841450dc7ddaa49352ab04
  • Pointer size: 129 Bytes
  • Size of remote file: 9.09 kB
test/Apple/Apple (1809).jpeg ADDED

Git LFS Details

  • SHA256: 17c532573a2e5733e5379847743371249607ef9a996035f615c229ce8a537f22
  • Pointer size: 130 Bytes
  • Size of remote file: 10.3 kB
test/Apple/Apple (1976).jpeg ADDED

Git LFS Details

  • SHA256: e9db2f0f5e29b31a985265f9ce7df38751503f4503f5743aca968ef03dcc6841
  • Pointer size: 130 Bytes
  • Size of remote file: 11.1 kB
test/Apple/Apple (233).jpeg ADDED

Git LFS Details

  • SHA256: bdfce8e468423193e926a1ce49aa02f06d22ef30dbd11642d3bec968d4096e9e
  • Pointer size: 129 Bytes
  • Size of remote file: 7.83 kB
test/Apple/Apple (27).jpeg ADDED

Git LFS Details

  • SHA256: dab3f953f813a7823cdc1e08fffa82f926bef3ae51bf9381809ade0d3a7282e0
  • Pointer size: 129 Bytes
  • Size of remote file: 6.83 kB
test/Apple/Apple (28).jpeg ADDED

Git LFS Details

  • SHA256: deb662094aaa6e7b6434697c9e6da122ee9d84ce12369d5c8365e00c6287b7d1
  • Pointer size: 129 Bytes
  • Size of remote file: 7.36 kB
test/Apple/Apple (420).jpeg ADDED

Git LFS Details

  • SHA256: 31a28f6219b234cec1b1714cfb4e5bc353e46a18196ef336ae7594d409e94a40
  • Pointer size: 130 Bytes
  • Size of remote file: 12.8 kB
test/Apple/Apple (545).jpeg ADDED

Git LFS Details

  • SHA256: b8f63800a4e84aaf7111e16389f50d4c0c3e484e1a7b5598189358fe90e2b299
  • Pointer size: 129 Bytes
  • Size of remote file: 8.83 kB
test/Banana/Banana (2044).jpeg ADDED

Git LFS Details

  • SHA256: 064f354551e1416f79c8854eb97f8a0ad8ee9cb9eb42fa82453b63ed8672ad2f
  • Pointer size: 129 Bytes
  • Size of remote file: 3.68 kB
test/Banana/Banana (2067).jpeg ADDED

Git LFS Details

  • SHA256: cca06a52de4881a3d158d2ef75559710b64123e649d9e79098d6560f7413b9de
  • Pointer size: 129 Bytes
  • Size of remote file: 8.38 kB
test/Banana/Banana (2120).jpeg ADDED

Git LFS Details

  • SHA256: 86998918bfe523c6f8721a9048594efa1deaff0319b785c959c97c2150844633
  • Pointer size: 130 Bytes
  • Size of remote file: 11.4 kB
test/Banana/Banana (2121).jpeg ADDED

Git LFS Details

  • SHA256: 7e2e1d5a229578827385284f35a74e6a0679695e49b651b7d8b2ef2e23d997f0
  • Pointer size: 130 Bytes
  • Size of remote file: 11.5 kB
test/Banana/Banana (2179).jpeg ADDED

Git LFS Details

  • SHA256: c9dcab91679075e9acecd0a391a30372b9bdde7814dc1ddc8bfafc47eab5e168
  • Pointer size: 130 Bytes
  • Size of remote file: 10.2 kB
test/Banana/Banana (2279).jpeg ADDED

Git LFS Details

  • SHA256: c36ab3fae0201debeb475a2c4c0e9ace05549bb60f644ac2e6cce893f5596bc9
  • Pointer size: 129 Bytes
  • Size of remote file: 4.22 kB
test/Banana/Banana (2291).jpeg ADDED

Git LFS Details

  • SHA256: 19fb5ee9485ab5039f7e6ba77fdf77e3c11ceb05459daa41a65c6bd395d82324
  • Pointer size: 130 Bytes
  • Size of remote file: 10.5 kB
test/Banana/Banana (2448).jpeg ADDED

Git LFS Details

  • SHA256: 522dcfc72c681b7d9cf6c8726c0cde9e51c76bd184ba5324a32d3561b22e142f
  • Pointer size: 130 Bytes
  • Size of remote file: 12.8 kB
test/Banana/Banana (2580).jpeg ADDED

Git LFS Details

  • SHA256: 0db88e7f0e8e6a8ed352b72fe5485e78031644b330fe1a3be89b18105bd642fe
  • Pointer size: 129 Bytes
  • Size of remote file: 4.46 kB
test/Banana/Banana (2712).jpeg ADDED

Git LFS Details

  • SHA256: f4b5c9d2e5aff00f43f1581bb63f7e060c5049fbcdd3f8c1f354eed14b379f4c
  • Pointer size: 129 Bytes
  • Size of remote file: 7.76 kB
test/Banana/Banana (2727).jpeg ADDED

Git LFS Details

  • SHA256: 83c99e5e9fe1af3ea5f95d21fc16359a13c7adc6af8147990478b2ba540f6fed
  • Pointer size: 129 Bytes
  • Size of remote file: 3.89 kB
test/Banana/Banana (2845).jpeg ADDED

Git LFS Details

  • SHA256: 6e8d18139695197e632ecdb06cb884800d340f0d7ea6ab469005ea78c8af4ba8
  • Pointer size: 129 Bytes
  • Size of remote file: 5.51 kB
test/Banana/Banana (2928).jpeg ADDED

Git LFS Details

  • SHA256: aee9253af54fee739e29cc64dc3edd624bf328fb57ac22f2b1d68d91c882aa4f
  • Pointer size: 129 Bytes
  • Size of remote file: 6.3 kB
test/Banana/Banana (3362).jpeg ADDED

Git LFS Details

  • SHA256: 6441114929d6b2028eaba90c3df33be925e1ab9b4fdc4d5bce68cfb9db8f2c2a
  • Pointer size: 129 Bytes
  • Size of remote file: 5.4 kB
test/Banana/Banana (3449).jpeg ADDED

Git LFS Details

  • SHA256: a14c5cfbd5fbb00e6db90cf96e6fcdafe810ef6c8533a5e184d856da5573e8d0
  • Pointer size: 129 Bytes
  • Size of remote file: 4.05 kB
test/Banana/Banana (3597).jpeg ADDED

Git LFS Details

  • SHA256: 27fc63d44dd206b495e2ae7c8a7dedea1ee596e6cb584b6872ba5d7398349d64
  • Pointer size: 129 Bytes
  • Size of remote file: 9.09 kB
test/Banana/Banana (3652).jpeg ADDED

Git LFS Details

  • SHA256: c4aaa826f9467eb5f87302d55e6352e01ba80f6624d4e447c0b4b5fd67fa664c
  • Pointer size: 130 Bytes
  • Size of remote file: 16.2 kB
test/Banana/Banana (3813).jpeg ADDED

Git LFS Details

  • SHA256: 660bc1bf46b3d419cdba613a895b715cc7440707272df173ac6c3f86f18d4247
  • Pointer size: 130 Bytes
  • Size of remote file: 10.4 kB
test/Banana/Banana (3901).jpeg ADDED

Git LFS Details

  • SHA256: f67f54545df2571741e798ef89c0b2f0f06da8ad55d51212da68f9c96c1bd491
  • Pointer size: 129 Bytes
  • Size of remote file: 9.46 kB
test/Banana/Banana (3939).jpeg ADDED

Git LFS Details

  • SHA256: fa07b498855dbcc4b27e8d65148bd3c526c7e1e83eb5d071acb093b17aaccdae
  • Pointer size: 129 Bytes
  • Size of remote file: 9.25 kB
test/Grape/Grape (1073).jpeg ADDED

Git LFS Details

  • SHA256: 0ea10b473989f7bbc78c3c7207e8ef1302d131e65ac7de03f92eaaf4decf5903
  • Pointer size: 129 Bytes
  • Size of remote file: 6.29 kB
test/Grape/Grape (1090).jpeg ADDED

Git LFS Details

  • SHA256: 346eb214f1aca52a8c946f7b127a8b47d8462cd72912144a67246f845de17846
  • Pointer size: 129 Bytes
  • Size of remote file: 8.92 kB
test/Grape/Grape (1222).jpeg ADDED

Git LFS Details

  • SHA256: b42da0d63ff2d1b9c140ddae6fb52732f0897cb6c63a2de05ac83f5360ab40e3
  • Pointer size: 129 Bytes
  • Size of remote file: 9.35 kB
test/Grape/Grape (1266).jpeg ADDED

Git LFS Details

  • SHA256: fa595abff0615f607983673635095902dc73b82b981bcd21df7c735bd125077e
  • Pointer size: 129 Bytes
  • Size of remote file: 7.18 kB
test/Grape/Grape (1335).jpeg ADDED

Git LFS Details

  • SHA256: f57bd159976eef2fa5ef4668a9f4b63c7d0badf2ce73ea635ed90b08a98230f0
  • Pointer size: 129 Bytes
  • Size of remote file: 3.76 kB
test/Grape/Grape (1470).jpeg ADDED

Git LFS Details

  • SHA256: 4e696296d5ab96541ef3a05c2a8b2a6de07b107bd37def3d84bb67f86cb2edbd
  • Pointer size: 129 Bytes
  • Size of remote file: 5.8 kB
test/Grape/Grape (1521).jpeg ADDED

Git LFS Details

  • SHA256: 017255fdf89ebd69ba41ecc67e3ed85507fd6763f4615dc47fc1f0c96b5e799c
  • Pointer size: 129 Bytes
  • Size of remote file: 7.41 kB
test/Grape/Grape (1575).jpeg ADDED

Git LFS Details

  • SHA256: 3fa3b5629fa2cfa25e4e2e390e4a22006409329106bbb62a784568afa21b9d4a
  • Pointer size: 129 Bytes
  • Size of remote file: 7.22 kB