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

get_data.py 1.2 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
  1. import os
  2. import yaml
  3. import pandas as pd
  4. import argparse
  5. import PIL
  6. def read_params(config_path):
  7. with open(config_path,'r') as yaml_file:
  8. config=yaml.safe_load(yaml_file)
  9. return config
  10. def get_data(config_path):
  11. config=read_params(config_path)
  12. #print(config)
  13. input_path = []
  14. label = []
  15. for clas in os.listdir("data_given"):
  16. for path in os.listdir("data_given/"+ clas):
  17. if clas == "Cat":
  18. label.append(0)
  19. else:
  20. label.append(1)
  21. input_path.append(os.path.join("data_given", clas, path))
  22. print(input_path[0], label[0])
  23. print(len(label))
  24. df = pd.DataFrame()
  25. df["image"] = input_path
  26. df["label"] = label
  27. df = df.sample(frac=1).reset_index(drop=True)
  28. df['label'] = df['label'].astype('str')
  29. df = df[df['image'] != 'PetImages/Cat/Thumbs.db']
  30. df = df[df['image'] != 'PetImages/Dog/Thumbs.db']
  31. df = df[df['image'] != 'PetImages/Cat/666.jpg']
  32. df = df[df['image'] != 'PetImages/Dog/11702.jpg']
  33. return df
  34. if __name__=="__main__":
  35. args=argparse.ArgumentParser()
  36. args.add_argument("--config",default="params.yaml")
  37. parsed_args=args.parse_args()
  38. data=get_data(config_path=parsed_args.config)
Tip!

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

Comments

Loading...