Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

data-prep.py 1.7 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon Feb 7 00:40:32 2022
  4. @author: AMIT CHAKRABORTY
  5. """
  6. import glob
  7. import os
  8. import shutil
  9. os.makedirs('classy/train_data', exist_ok =True)
  10. os.makedirs('classy/val_data', exist_ok =True)
  11. parent_dir1 = 'classy/train_data'
  12. parent_dir2 = 'classy/val_data'
  13. dir_miss = 'miss'
  14. dir_no = 'nomiss'
  15. path1 = os.path.join(parent_dir1, dir_miss)
  16. path2 = os.path.join(parent_dir2, dir_miss)
  17. path3 = os.path.join(parent_dir1, dir_no)
  18. path4 = os.path.join(parent_dir2, dir_no)
  19. #############################################
  20. os.makedirs(path1, exist_ok = True)
  21. os.makedirs(path2, exist_ok =True)
  22. os.makedirs(path3, exist_ok = True)
  23. os.makedirs(path4, exist_ok =True)
  24. ##############################################
  25. def data_prep():
  26. folders = os.listdir('classy/miss')
  27. file_mark = len(folders)*0.75
  28. i = 0
  29. for f in folders:
  30. if (i < file_mark):
  31. source = os.path.join('classy/miss', f)
  32. dest = os.path.join(path1, f)
  33. shutil.copy(source, dest)
  34. else:
  35. source = os.path.join('classy/miss', f)
  36. dest = os.path.join(path2, f)
  37. shutil.copy(source, dest)
  38. i = i + 1
  39. ################################################
  40. files1 = os.listdir('classy/nomiss')
  41. file_mark = len(files1)*0.75
  42. i = 0
  43. for f in files1:
  44. if (i < file_mark):
  45. source = os.path.join('classy/nomiss', f)
  46. dest = os.path.join(path3, f)
  47. shutil.copy(source, dest)
  48. else:
  49. source = os.path.join('classy/nomiss', f)
  50. dest = os.path.join(path4, f)
  51. shutil.copy(source, dest)
  52. i = i + 1
  53. if __name__ == '__main__':
  54. data_prep()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...