bplusplus 1.1.0__py3-none-any.whl → 1.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of bplusplus might be problematic. Click here for more details.

Files changed (97) hide show
  1. bplusplus/__init__.py +4 -2
  2. bplusplus/collect.py +69 -5
  3. bplusplus/hierarchical/test.py +670 -0
  4. bplusplus/hierarchical/train.py +676 -0
  5. bplusplus/prepare.py +228 -64
  6. bplusplus/resnet/test.py +473 -0
  7. bplusplus/resnet/train.py +329 -0
  8. bplusplus-1.2.0.dist-info/METADATA +249 -0
  9. bplusplus-1.2.0.dist-info/RECORD +12 -0
  10. bplusplus/yolov5detect/__init__.py +0 -1
  11. bplusplus/yolov5detect/detect.py +0 -444
  12. bplusplus/yolov5detect/export.py +0 -1530
  13. bplusplus/yolov5detect/insect.yaml +0 -8
  14. bplusplus/yolov5detect/models/__init__.py +0 -0
  15. bplusplus/yolov5detect/models/common.py +0 -1109
  16. bplusplus/yolov5detect/models/experimental.py +0 -130
  17. bplusplus/yolov5detect/models/hub/anchors.yaml +0 -56
  18. bplusplus/yolov5detect/models/hub/yolov3-spp.yaml +0 -52
  19. bplusplus/yolov5detect/models/hub/yolov3-tiny.yaml +0 -42
  20. bplusplus/yolov5detect/models/hub/yolov3.yaml +0 -52
  21. bplusplus/yolov5detect/models/hub/yolov5-bifpn.yaml +0 -49
  22. bplusplus/yolov5detect/models/hub/yolov5-fpn.yaml +0 -43
  23. bplusplus/yolov5detect/models/hub/yolov5-p2.yaml +0 -55
  24. bplusplus/yolov5detect/models/hub/yolov5-p34.yaml +0 -42
  25. bplusplus/yolov5detect/models/hub/yolov5-p6.yaml +0 -57
  26. bplusplus/yolov5detect/models/hub/yolov5-p7.yaml +0 -68
  27. bplusplus/yolov5detect/models/hub/yolov5-panet.yaml +0 -49
  28. bplusplus/yolov5detect/models/hub/yolov5l6.yaml +0 -61
  29. bplusplus/yolov5detect/models/hub/yolov5m6.yaml +0 -61
  30. bplusplus/yolov5detect/models/hub/yolov5n6.yaml +0 -61
  31. bplusplus/yolov5detect/models/hub/yolov5s-LeakyReLU.yaml +0 -50
  32. bplusplus/yolov5detect/models/hub/yolov5s-ghost.yaml +0 -49
  33. bplusplus/yolov5detect/models/hub/yolov5s-transformer.yaml +0 -49
  34. bplusplus/yolov5detect/models/hub/yolov5s6.yaml +0 -61
  35. bplusplus/yolov5detect/models/hub/yolov5x6.yaml +0 -61
  36. bplusplus/yolov5detect/models/segment/yolov5l-seg.yaml +0 -49
  37. bplusplus/yolov5detect/models/segment/yolov5m-seg.yaml +0 -49
  38. bplusplus/yolov5detect/models/segment/yolov5n-seg.yaml +0 -49
  39. bplusplus/yolov5detect/models/segment/yolov5s-seg.yaml +0 -49
  40. bplusplus/yolov5detect/models/segment/yolov5x-seg.yaml +0 -49
  41. bplusplus/yolov5detect/models/tf.py +0 -797
  42. bplusplus/yolov5detect/models/yolo.py +0 -495
  43. bplusplus/yolov5detect/models/yolov5l.yaml +0 -49
  44. bplusplus/yolov5detect/models/yolov5m.yaml +0 -49
  45. bplusplus/yolov5detect/models/yolov5n.yaml +0 -49
  46. bplusplus/yolov5detect/models/yolov5s.yaml +0 -49
  47. bplusplus/yolov5detect/models/yolov5x.yaml +0 -49
  48. bplusplus/yolov5detect/utils/__init__.py +0 -97
  49. bplusplus/yolov5detect/utils/activations.py +0 -134
  50. bplusplus/yolov5detect/utils/augmentations.py +0 -448
  51. bplusplus/yolov5detect/utils/autoanchor.py +0 -175
  52. bplusplus/yolov5detect/utils/autobatch.py +0 -70
  53. bplusplus/yolov5detect/utils/aws/__init__.py +0 -0
  54. bplusplus/yolov5detect/utils/aws/mime.sh +0 -26
  55. bplusplus/yolov5detect/utils/aws/resume.py +0 -41
  56. bplusplus/yolov5detect/utils/aws/userdata.sh +0 -27
  57. bplusplus/yolov5detect/utils/callbacks.py +0 -72
  58. bplusplus/yolov5detect/utils/dataloaders.py +0 -1385
  59. bplusplus/yolov5detect/utils/docker/Dockerfile +0 -73
  60. bplusplus/yolov5detect/utils/docker/Dockerfile-arm64 +0 -40
  61. bplusplus/yolov5detect/utils/docker/Dockerfile-cpu +0 -42
  62. bplusplus/yolov5detect/utils/downloads.py +0 -136
  63. bplusplus/yolov5detect/utils/flask_rest_api/README.md +0 -70
  64. bplusplus/yolov5detect/utils/flask_rest_api/example_request.py +0 -17
  65. bplusplus/yolov5detect/utils/flask_rest_api/restapi.py +0 -49
  66. bplusplus/yolov5detect/utils/general.py +0 -1294
  67. bplusplus/yolov5detect/utils/google_app_engine/Dockerfile +0 -25
  68. bplusplus/yolov5detect/utils/google_app_engine/additional_requirements.txt +0 -6
  69. bplusplus/yolov5detect/utils/google_app_engine/app.yaml +0 -16
  70. bplusplus/yolov5detect/utils/loggers/__init__.py +0 -476
  71. bplusplus/yolov5detect/utils/loggers/clearml/README.md +0 -222
  72. bplusplus/yolov5detect/utils/loggers/clearml/__init__.py +0 -0
  73. bplusplus/yolov5detect/utils/loggers/clearml/clearml_utils.py +0 -230
  74. bplusplus/yolov5detect/utils/loggers/clearml/hpo.py +0 -90
  75. bplusplus/yolov5detect/utils/loggers/comet/README.md +0 -250
  76. bplusplus/yolov5detect/utils/loggers/comet/__init__.py +0 -551
  77. bplusplus/yolov5detect/utils/loggers/comet/comet_utils.py +0 -151
  78. bplusplus/yolov5detect/utils/loggers/comet/hpo.py +0 -126
  79. bplusplus/yolov5detect/utils/loggers/comet/optimizer_config.json +0 -135
  80. bplusplus/yolov5detect/utils/loggers/wandb/__init__.py +0 -0
  81. bplusplus/yolov5detect/utils/loggers/wandb/wandb_utils.py +0 -210
  82. bplusplus/yolov5detect/utils/loss.py +0 -259
  83. bplusplus/yolov5detect/utils/metrics.py +0 -381
  84. bplusplus/yolov5detect/utils/plots.py +0 -517
  85. bplusplus/yolov5detect/utils/segment/__init__.py +0 -0
  86. bplusplus/yolov5detect/utils/segment/augmentations.py +0 -100
  87. bplusplus/yolov5detect/utils/segment/dataloaders.py +0 -366
  88. bplusplus/yolov5detect/utils/segment/general.py +0 -160
  89. bplusplus/yolov5detect/utils/segment/loss.py +0 -198
  90. bplusplus/yolov5detect/utils/segment/metrics.py +0 -225
  91. bplusplus/yolov5detect/utils/segment/plots.py +0 -152
  92. bplusplus/yolov5detect/utils/torch_utils.py +0 -482
  93. bplusplus/yolov5detect/utils/triton.py +0 -90
  94. bplusplus-1.1.0.dist-info/METADATA +0 -179
  95. bplusplus-1.1.0.dist-info/RECORD +0 -92
  96. {bplusplus-1.1.0.dist-info → bplusplus-1.2.0.dist-info}/LICENSE +0 -0
  97. {bplusplus-1.1.0.dist-info → bplusplus-1.2.0.dist-info}/WHEEL +0 -0
bplusplus/__init__.py CHANGED
@@ -1,5 +1,7 @@
1
1
  from .collect import Group, collect
2
2
  from .train_validate import train, validate
3
3
  from .prepare import prepare
4
- from .yolov5detect.detect import run
5
-
4
+ from .resnet.train import train_resnet
5
+ from .resnet.test import test_resnet
6
+ from .hierarchical.train import train_multitask
7
+ from .hierarchical.test import test_multitask
bplusplus/collect.py CHANGED
@@ -1,22 +1,41 @@
1
1
  import os
2
2
  import random
3
+ import threading
3
4
  from enum import Enum
4
- from typing import Any, Optional
5
-
5
+ from typing import Any, Optional, List, Dict
6
+ from tqdm import tqdm
7
+ import random
6
8
  import pygbif
7
9
  import requests
8
10
  import validators
9
11
 
10
-
11
12
  #this lists currently supported groupings, more can be added with proper testing
12
13
  class Group(str, Enum):
13
14
  scientificName="scientificName"
14
15
 
15
16
  #TODO add back support for fetching from dataset (or csvs)
16
- def collect(group_by_key: Group, search_parameters: dict[str, Any], images_per_group: int, output_directory: str):
17
+ def collect(group_by_key: Group, search_parameters: dict[str, Any], images_per_group: int, output_directory: str, num_threads: int):
17
18
 
18
19
  groups: list[str] = search_parameters[group_by_key.value]
19
20
 
21
+ # check if user wants to parallelize the process
22
+ if num_threads > 1:
23
+ __threaded_collect(
24
+ images_per_group=images_per_group,
25
+ output_directory=output_directory,
26
+ num_threads=num_threads,
27
+ groups=groups)
28
+ else:
29
+ __single_collect(
30
+ search_parameters=search_parameters,
31
+ images_per_group=images_per_group,
32
+ output_directory=output_directory,
33
+ group_by_key=group_by_key,
34
+ groups=groups,
35
+ )
36
+
37
+ def __single_collect(group_by_key: Group, search_parameters: dict[str, Any], images_per_group: int, output_directory: str, groups: list[str]):
38
+
20
39
  #TODO throw error if groups is not a str list
21
40
 
22
41
  __create_folders(
@@ -37,7 +56,7 @@ def collect(group_by_key: Group, search_parameters: dict[str, Any], images_per_g
37
56
  sampled_occurrences = random.sample(occurrences, min(images_per_group, len(occurrences)))
38
57
 
39
58
  print(f"Downloading {len(sampled_occurrences)} images into the {group} folder...")
40
- for occurrence in sampled_occurrences:
59
+ for occurrence in tqdm(sampled_occurrences, desc=f"Downloading images for {group}", unit="image"):
41
60
  # image_url = occurrence.image_url.replace("original", "large") # hack to get max 1024px image
42
61
 
43
62
  __down_image(
@@ -49,6 +68,34 @@ def collect(group_by_key: Group, search_parameters: dict[str, Any], images_per_g
49
68
 
50
69
  print("Finished collecting images.")
51
70
 
71
+ # threaded_collect: paralellize the collection of images
72
+ def __threaded_collect(images_per_group: int, output_directory: str, num_threads: int, groups: list[str]):
73
+ # Divide the species list into num_threads parts
74
+ chunk_size = len(groups) // num_threads
75
+ species_chunks = [
76
+ groups[i:i + chunk_size] for i in range(0, len(groups), chunk_size)
77
+ ]
78
+
79
+ # Ensure we have exactly num_threads chunks (the last chunk might be larger if len(species_list) % num_threads != 0)
80
+ while len(species_chunks) < num_threads:
81
+ species_chunks.append([])
82
+
83
+ threads = []
84
+ for i, chunk in enumerate(species_chunks):
85
+ thread = threading.Thread(
86
+ target=__collect_subset,
87
+ args=(chunk, images_per_group, output_directory, i)
88
+ )
89
+ threads.append(thread)
90
+ thread.start()
91
+
92
+ # Wait for all threads to complete
93
+ for thread in threads:
94
+ thread.join()
95
+
96
+ print("All collection threads have finished.")
97
+
98
+
52
99
  def _fetch_occurrences(group_key: str, group_value: str, parameters: dict[str, Any], totalLimit: int) -> list[dict[str, Any]]:
53
100
  parameters[group_key] = group_value
54
101
  return __next_batch(
@@ -98,6 +145,23 @@ def __create_folders(names: list[str], directory: str):
98
145
  # Create a folder using the group name
99
146
  os.makedirs(folder_name, exist_ok=True)
100
147
 
148
+ def __collect_subset(species_subset: List[str], images_per_group: int, output_directory: str, thread_id: int):
149
+ search_subset: Dict[str, Any] = {
150
+ "scientificName": species_subset
151
+ }
152
+
153
+ print(f"Thread {thread_id} starting collection for {len(species_subset)} species.")
154
+
155
+ __single_collect(
156
+ search_parameters=search_subset,
157
+ images_per_group=images_per_group,
158
+ output_directory=output_directory,
159
+ group_by_key=Group.scientificName,
160
+ groups=species_subset
161
+ )
162
+
163
+ print(f"Thread {thread_id} finished collection.")
164
+
101
165
 
102
166
 
103
167