wandb 0.13.10__py3-none-any.whl → 0.14.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (228) hide show
  1. wandb/__init__.py +2 -3
  2. wandb/apis/__init__.py +1 -3
  3. wandb/apis/importers/__init__.py +4 -0
  4. wandb/apis/importers/base.py +312 -0
  5. wandb/apis/importers/mlflow.py +113 -0
  6. wandb/apis/internal.py +29 -2
  7. wandb/apis/normalize.py +6 -5
  8. wandb/apis/public.py +163 -180
  9. wandb/apis/reports/_templates.py +6 -12
  10. wandb/apis/reports/report.py +1 -1
  11. wandb/apis/reports/runset.py +1 -3
  12. wandb/apis/reports/util.py +12 -10
  13. wandb/beta/workflows.py +57 -34
  14. wandb/catboost/__init__.py +1 -2
  15. wandb/cli/cli.py +215 -133
  16. wandb/data_types.py +63 -56
  17. wandb/docker/__init__.py +78 -16
  18. wandb/docker/auth.py +21 -22
  19. wandb/env.py +0 -1
  20. wandb/errors/__init__.py +8 -116
  21. wandb/errors/term.py +1 -1
  22. wandb/fastai/__init__.py +1 -2
  23. wandb/filesync/dir_watcher.py +8 -5
  24. wandb/filesync/step_prepare.py +76 -75
  25. wandb/filesync/step_upload.py +1 -2
  26. wandb/integration/catboost/__init__.py +1 -3
  27. wandb/integration/catboost/catboost.py +8 -14
  28. wandb/integration/fastai/__init__.py +7 -13
  29. wandb/integration/gym/__init__.py +35 -4
  30. wandb/integration/keras/__init__.py +3 -3
  31. wandb/integration/keras/callbacks/metrics_logger.py +9 -8
  32. wandb/integration/keras/callbacks/model_checkpoint.py +9 -9
  33. wandb/integration/keras/callbacks/tables_builder.py +31 -19
  34. wandb/integration/kfp/kfp_patch.py +20 -17
  35. wandb/integration/kfp/wandb_logging.py +1 -2
  36. wandb/integration/lightgbm/__init__.py +21 -19
  37. wandb/integration/prodigy/prodigy.py +6 -7
  38. wandb/integration/sacred/__init__.py +9 -12
  39. wandb/integration/sagemaker/__init__.py +1 -3
  40. wandb/integration/sagemaker/auth.py +0 -1
  41. wandb/integration/sagemaker/config.py +1 -1
  42. wandb/integration/sagemaker/resources.py +1 -1
  43. wandb/integration/sb3/sb3.py +8 -4
  44. wandb/integration/tensorboard/__init__.py +1 -3
  45. wandb/integration/tensorboard/log.py +8 -8
  46. wandb/integration/tensorboard/monkeypatch.py +11 -9
  47. wandb/integration/tensorflow/__init__.py +1 -3
  48. wandb/integration/xgboost/__init__.py +4 -6
  49. wandb/integration/yolov8/__init__.py +7 -0
  50. wandb/integration/yolov8/yolov8.py +250 -0
  51. wandb/jupyter.py +31 -35
  52. wandb/lightgbm/__init__.py +1 -2
  53. wandb/old/settings.py +2 -2
  54. wandb/plot/bar.py +1 -2
  55. wandb/plot/confusion_matrix.py +1 -3
  56. wandb/plot/histogram.py +1 -2
  57. wandb/plot/line.py +1 -2
  58. wandb/plot/line_series.py +4 -4
  59. wandb/plot/pr_curve.py +17 -20
  60. wandb/plot/roc_curve.py +1 -3
  61. wandb/plot/scatter.py +1 -2
  62. wandb/proto/v3/wandb_server_pb2.py +85 -39
  63. wandb/proto/v3/wandb_telemetry_pb2.py +10 -10
  64. wandb/proto/v4/wandb_server_pb2.py +51 -39
  65. wandb/proto/v4/wandb_telemetry_pb2.py +10 -10
  66. wandb/sdk/__init__.py +1 -3
  67. wandb/sdk/backend/backend.py +1 -1
  68. wandb/sdk/data_types/_dtypes.py +38 -30
  69. wandb/sdk/data_types/base_types/json_metadata.py +1 -3
  70. wandb/sdk/data_types/base_types/media.py +17 -17
  71. wandb/sdk/data_types/base_types/wb_value.py +33 -26
  72. wandb/sdk/data_types/helper_types/bounding_boxes_2d.py +91 -125
  73. wandb/sdk/data_types/helper_types/classes.py +1 -1
  74. wandb/sdk/data_types/helper_types/image_mask.py +12 -12
  75. wandb/sdk/data_types/histogram.py +5 -4
  76. wandb/sdk/data_types/html.py +1 -2
  77. wandb/sdk/data_types/image.py +11 -11
  78. wandb/sdk/data_types/molecule.py +3 -6
  79. wandb/sdk/data_types/object_3d.py +1 -2
  80. wandb/sdk/data_types/plotly.py +1 -2
  81. wandb/sdk/data_types/saved_model.py +10 -8
  82. wandb/sdk/data_types/video.py +1 -1
  83. wandb/sdk/integration_utils/data_logging.py +5 -5
  84. wandb/sdk/interface/artifacts.py +288 -266
  85. wandb/sdk/interface/interface.py +2 -3
  86. wandb/sdk/interface/interface_grpc.py +1 -1
  87. wandb/sdk/interface/interface_queue.py +1 -1
  88. wandb/sdk/interface/interface_relay.py +1 -1
  89. wandb/sdk/interface/interface_shared.py +1 -2
  90. wandb/sdk/interface/interface_sock.py +1 -1
  91. wandb/sdk/interface/message_future.py +1 -1
  92. wandb/sdk/interface/message_future_poll.py +1 -1
  93. wandb/sdk/interface/router.py +1 -1
  94. wandb/sdk/interface/router_queue.py +1 -1
  95. wandb/sdk/interface/router_relay.py +1 -1
  96. wandb/sdk/interface/router_sock.py +1 -1
  97. wandb/sdk/interface/summary_record.py +1 -1
  98. wandb/sdk/internal/artifacts.py +1 -1
  99. wandb/sdk/internal/datastore.py +2 -3
  100. wandb/sdk/internal/file_pusher.py +5 -3
  101. wandb/sdk/internal/file_stream.py +22 -19
  102. wandb/sdk/internal/handler.py +5 -4
  103. wandb/sdk/internal/internal.py +1 -1
  104. wandb/sdk/internal/internal_api.py +115 -55
  105. wandb/sdk/internal/job_builder.py +1 -3
  106. wandb/sdk/internal/profiler.py +1 -1
  107. wandb/sdk/internal/progress.py +4 -6
  108. wandb/sdk/internal/sample.py +1 -3
  109. wandb/sdk/internal/sender.py +28 -16
  110. wandb/sdk/internal/settings_static.py +5 -5
  111. wandb/sdk/internal/system/assets/__init__.py +1 -0
  112. wandb/sdk/internal/system/assets/cpu.py +3 -9
  113. wandb/sdk/internal/system/assets/disk.py +2 -4
  114. wandb/sdk/internal/system/assets/gpu.py +6 -18
  115. wandb/sdk/internal/system/assets/gpu_apple.py +2 -4
  116. wandb/sdk/internal/system/assets/interfaces.py +50 -22
  117. wandb/sdk/internal/system/assets/ipu.py +1 -3
  118. wandb/sdk/internal/system/assets/memory.py +7 -13
  119. wandb/sdk/internal/system/assets/network.py +4 -8
  120. wandb/sdk/internal/system/assets/open_metrics.py +283 -0
  121. wandb/sdk/internal/system/assets/tpu.py +1 -4
  122. wandb/sdk/internal/system/assets/trainium.py +26 -14
  123. wandb/sdk/internal/system/system_info.py +2 -3
  124. wandb/sdk/internal/system/system_monitor.py +52 -20
  125. wandb/sdk/internal/tb_watcher.py +12 -13
  126. wandb/sdk/launch/_project_spec.py +54 -65
  127. wandb/sdk/launch/agent/agent.py +374 -90
  128. wandb/sdk/launch/builder/abstract.py +61 -7
  129. wandb/sdk/launch/builder/build.py +81 -110
  130. wandb/sdk/launch/builder/docker_builder.py +181 -0
  131. wandb/sdk/launch/builder/kaniko_builder.py +419 -0
  132. wandb/sdk/launch/builder/noop.py +31 -12
  133. wandb/sdk/launch/builder/templates/_wandb_bootstrap.py +70 -20
  134. wandb/sdk/launch/environment/abstract.py +28 -0
  135. wandb/sdk/launch/environment/aws_environment.py +276 -0
  136. wandb/sdk/launch/environment/gcp_environment.py +271 -0
  137. wandb/sdk/launch/environment/local_environment.py +65 -0
  138. wandb/sdk/launch/github_reference.py +3 -8
  139. wandb/sdk/launch/launch.py +38 -29
  140. wandb/sdk/launch/launch_add.py +6 -8
  141. wandb/sdk/launch/loader.py +230 -0
  142. wandb/sdk/launch/registry/abstract.py +54 -0
  143. wandb/sdk/launch/registry/elastic_container_registry.py +163 -0
  144. wandb/sdk/launch/registry/google_artifact_registry.py +203 -0
  145. wandb/sdk/launch/registry/local_registry.py +62 -0
  146. wandb/sdk/launch/runner/abstract.py +1 -16
  147. wandb/sdk/launch/runner/{kubernetes.py → kubernetes_runner.py} +83 -95
  148. wandb/sdk/launch/runner/local_container.py +46 -22
  149. wandb/sdk/launch/runner/local_process.py +1 -4
  150. wandb/sdk/launch/runner/{aws.py → sagemaker_runner.py} +53 -212
  151. wandb/sdk/launch/runner/{gcp_vertex.py → vertex_runner.py} +38 -55
  152. wandb/sdk/launch/sweeps/__init__.py +3 -2
  153. wandb/sdk/launch/sweeps/scheduler.py +132 -39
  154. wandb/sdk/launch/sweeps/scheduler_sweep.py +80 -89
  155. wandb/sdk/launch/utils.py +101 -30
  156. wandb/sdk/launch/wandb_reference.py +2 -7
  157. wandb/sdk/lib/_settings_toposort_generate.py +166 -0
  158. wandb/sdk/lib/_settings_toposort_generated.py +201 -0
  159. wandb/sdk/lib/apikey.py +2 -4
  160. wandb/sdk/lib/config_util.py +4 -1
  161. wandb/sdk/lib/console.py +1 -3
  162. wandb/sdk/lib/deprecate.py +3 -3
  163. wandb/sdk/lib/file_stream_utils.py +7 -5
  164. wandb/sdk/lib/filenames.py +1 -1
  165. wandb/sdk/lib/filesystem.py +61 -5
  166. wandb/sdk/lib/git.py +1 -3
  167. wandb/sdk/lib/import_hooks.py +4 -7
  168. wandb/sdk/lib/ipython.py +8 -5
  169. wandb/sdk/lib/lazyloader.py +1 -3
  170. wandb/sdk/lib/mailbox.py +14 -4
  171. wandb/sdk/lib/proto_util.py +10 -5
  172. wandb/sdk/lib/redirect.py +15 -22
  173. wandb/sdk/lib/reporting.py +1 -3
  174. wandb/sdk/lib/retry.py +4 -5
  175. wandb/sdk/lib/runid.py +1 -3
  176. wandb/sdk/lib/server.py +15 -9
  177. wandb/sdk/lib/sock_client.py +1 -1
  178. wandb/sdk/lib/sparkline.py +1 -1
  179. wandb/sdk/lib/wburls.py +1 -1
  180. wandb/sdk/service/port_file.py +1 -2
  181. wandb/sdk/service/service.py +36 -13
  182. wandb/sdk/service/service_base.py +12 -1
  183. wandb/sdk/verify/verify.py +5 -7
  184. wandb/sdk/wandb_artifacts.py +142 -177
  185. wandb/sdk/wandb_config.py +5 -8
  186. wandb/sdk/wandb_helper.py +1 -1
  187. wandb/sdk/wandb_init.py +24 -13
  188. wandb/sdk/wandb_login.py +9 -9
  189. wandb/sdk/wandb_manager.py +39 -4
  190. wandb/sdk/wandb_metric.py +2 -6
  191. wandb/sdk/wandb_require.py +4 -15
  192. wandb/sdk/wandb_require_helpers.py +1 -9
  193. wandb/sdk/wandb_run.py +95 -141
  194. wandb/sdk/wandb_save.py +1 -3
  195. wandb/sdk/wandb_settings.py +149 -54
  196. wandb/sdk/wandb_setup.py +66 -46
  197. wandb/sdk/wandb_summary.py +13 -10
  198. wandb/sdk/wandb_sweep.py +6 -7
  199. wandb/sdk/wandb_watch.py +1 -1
  200. wandb/sklearn/calculate/confusion_matrix.py +1 -1
  201. wandb/sklearn/calculate/learning_curve.py +1 -1
  202. wandb/sklearn/calculate/summary_metrics.py +1 -3
  203. wandb/sklearn/plot/__init__.py +1 -1
  204. wandb/sklearn/plot/classifier.py +27 -18
  205. wandb/sklearn/plot/clusterer.py +4 -5
  206. wandb/sklearn/plot/regressor.py +4 -4
  207. wandb/sklearn/plot/shared.py +2 -2
  208. wandb/sync/__init__.py +1 -3
  209. wandb/sync/sync.py +4 -5
  210. wandb/testing/relay.py +11 -10
  211. wandb/trigger.py +1 -1
  212. wandb/util.py +106 -81
  213. wandb/viz.py +4 -4
  214. wandb/wandb_agent.py +50 -50
  215. wandb/wandb_controller.py +2 -3
  216. wandb/wandb_run.py +1 -2
  217. wandb/wandb_torch.py +1 -1
  218. wandb/xgboost/__init__.py +1 -2
  219. {wandb-0.13.10.dist-info → wandb-0.14.0.dist-info}/METADATA +6 -2
  220. {wandb-0.13.10.dist-info → wandb-0.14.0.dist-info}/RECORD +224 -209
  221. {wandb-0.13.10.dist-info → wandb-0.14.0.dist-info}/WHEEL +1 -1
  222. wandb/sdk/launch/builder/docker.py +0 -80
  223. wandb/sdk/launch/builder/kaniko.py +0 -393
  224. wandb/sdk/launch/builder/loader.py +0 -32
  225. wandb/sdk/launch/runner/loader.py +0 -50
  226. {wandb-0.13.10.dist-info → wandb-0.14.0.dist-info}/LICENSE +0 -0
  227. {wandb-0.13.10.dist-info → wandb-0.14.0.dist-info}/entry_points.txt +0 -0
  228. {wandb-0.13.10.dist-info → wandb-0.14.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,7 @@
1
+ """Tools for integrating `wandb` with [`ultralytics YOLOv8`](https://docs.ultralytics.com/).
2
+
3
+ YOLOv8 is a computer vision framework for training and deploying YOLOv8 models.
4
+ """
5
+ __all__ = ("add_callbacks",)
6
+
7
+ from .yolov8 import add_callbacks
@@ -0,0 +1,250 @@
1
+ from typing import Any, Callable, Dict, List, Optional
2
+
3
+ from ultralytics.yolo.engine.model import YOLO
4
+ from ultralytics.yolo.engine.trainer import BaseTrainer
5
+ from ultralytics.yolo.utils import RANK
6
+ from ultralytics.yolo.utils.torch_utils import get_flops, get_num_params
7
+ from ultralytics.yolo.v8.classify.train import ClassificationTrainer
8
+
9
+ import wandb
10
+ from wandb.sdk.lib import telemetry
11
+
12
+
13
+ class WandbCallback:
14
+ """An internal YOLO model wrapper that tracks metrics, and logs models to Weights & Biases.
15
+
16
+ Usage:
17
+ ```python
18
+ from wandb.integration.yolov8.yolov8 import WandbCallback
19
+ model = YOLO("yolov8n.pt")
20
+ wandb_logger = WandbCallback(model,)
21
+ for event, callback_fn in wandb_logger.callbacks.items():
22
+ model.add_callback(event, callback_fn)
23
+ ```
24
+ """
25
+
26
+ def __init__(
27
+ self,
28
+ yolo: YOLO,
29
+ run_name: Optional[str] = None,
30
+ project: Optional[str] = None,
31
+ tags: Optional[List[str]] = None,
32
+ resume: Optional[str] = None,
33
+ **kwargs: Optional[Any],
34
+ ) -> None:
35
+ """A utility class to manage wandb run and various callbacks for the ultralytics YOLOv8 framework.
36
+
37
+ Args:
38
+ yolo: A YOLOv8 model that's inherited from `:class:ultralytics.yolo.engine.model.YOLO`
39
+ run_name, str: The name of the Weights & Biases run, defaults to an auto generated run_name if `trainer.args.name` is not defined.
40
+ project, str: The name of the Weights & Biases project, defaults to `"YOLOv8"` if `trainer.args.project` is not defined.
41
+ tags, List[str]: A list of tags to be added to the Weights & Biases run, defaults to `["YOLOv8"]`.
42
+ resume, str: Whether to resume a previous run on Weights & Biases, defaults to `None`.
43
+ **kwargs: Additional arguments to be passed to `wandb.init()`.
44
+ """
45
+ self.yolo = yolo
46
+ self.run_name = run_name
47
+ self.project = project
48
+ self.tags = tags
49
+ self.resume = resume
50
+ self.kwargs = kwargs
51
+
52
+ def on_pretrain_routine_start(self, trainer: BaseTrainer) -> None:
53
+ """Starts a new wandb run to track the training process and log to Weights & Biases.
54
+
55
+ Args:
56
+ trainer: A task trainer that's inherited from `:class:ultralytics.yolo.engine.trainer.BaseTrainer`
57
+ that contains the model training and optimization routine.
58
+ """
59
+ if wandb.run is None:
60
+ self.run = wandb.init(
61
+ name=self.run_name if self.run_name else trainer.args.name,
62
+ project=self.project
63
+ if self.project
64
+ else trainer.args.project or "YOLOv8",
65
+ tags=self.tags if self.tags else ["YOLOv8"],
66
+ config=vars(trainer.args),
67
+ resume=self.resume if self.resume else None,
68
+ **self.kwargs,
69
+ )
70
+ else:
71
+ self.run = wandb.run
72
+ self.run.define_metric("epoch", hidden=True)
73
+ self.run.define_metric(
74
+ "train/*", step_metric="epoch", step_sync=True, summary="min"
75
+ )
76
+
77
+ self.run.define_metric(
78
+ "val/*", step_metric="epoch", step_sync=True, summary="min"
79
+ )
80
+
81
+ self.run.define_metric(
82
+ "metrics/*", step_metric="epoch", step_sync=True, summary="max"
83
+ )
84
+ self.run.define_metric(
85
+ "lr/*", step_metric="epoch", step_sync=True, summary="last"
86
+ )
87
+
88
+ with telemetry.context(run=wandb.run) as tel:
89
+ tel.feature.ultralytics_yolov8 = True
90
+
91
+ def on_pretrain_routine_end(self, trainer: BaseTrainer) -> None:
92
+ self.run.summary.update(
93
+ {
94
+ "model/parameters": get_num_params(trainer.model),
95
+ "model/GFLOPs": round(get_flops(trainer.model), 3),
96
+ }
97
+ )
98
+
99
+ def on_train_epoch_start(self, trainer: BaseTrainer) -> None:
100
+ """On train epoch start we only log epoch number to the Weights & Biases run."""
101
+ # We log the epoch number here to commit the previous step,
102
+ self.run.log({"epoch": trainer.epoch + 1})
103
+
104
+ def on_train_epoch_end(self, trainer: BaseTrainer) -> None:
105
+ """On train epoch end we log all the metrics to the Weights & Biases run."""
106
+ self.run.log(
107
+ {
108
+ **trainer.metrics,
109
+ **trainer.label_loss_items(trainer.tloss, prefix="train"),
110
+ **trainer.lr,
111
+ },
112
+ )
113
+ # Currently only the detection and segmentation trainers save images to the save_dir
114
+ if not isinstance(trainer, ClassificationTrainer):
115
+ self.run.log(
116
+ {
117
+ "train_batch_images": [
118
+ wandb.Image(str(image_path), caption=image_path.stem)
119
+ for image_path in trainer.save_dir.glob("train_batch*.jpg")
120
+ ]
121
+ }
122
+ )
123
+
124
+ def on_fit_epoch_end(self, trainer: BaseTrainer) -> None:
125
+ """On fit epoch end we log all the best metrics and model detail to Weights & Biases run summary."""
126
+ if trainer.epoch == 0:
127
+ speeds = [
128
+ trainer.validator.speed.get(
129
+ key,
130
+ )
131
+ for key in (1, "inference")
132
+ ]
133
+ speed = speeds[0] if speeds[0] else speeds[1]
134
+ if speed:
135
+ self.run.summary.update(
136
+ {
137
+ "model/speed(ms/img)": round(speed, 3),
138
+ }
139
+ )
140
+ if trainer.best_fitness == trainer.fitness:
141
+ self.run.summary.update(
142
+ {
143
+ "best/epoch": trainer.epoch + 1,
144
+ **{f"best/{key}": val for key, val in trainer.metrics.items()},
145
+ }
146
+ )
147
+
148
+ def on_train_end(self, trainer: BaseTrainer) -> None:
149
+ """On train end we log all the media, including plots, images and best model artifact to Weights & Biases."""
150
+ # Currently only the detection and segmentation trainers save images to the save_dir
151
+ if not isinstance(trainer, ClassificationTrainer):
152
+ self.run.log(
153
+ {
154
+ "plots": [
155
+ wandb.Image(str(image_path), caption=image_path.stem)
156
+ for image_path in trainer.save_dir.glob("*.png")
157
+ ],
158
+ "val_images": [
159
+ wandb.Image(str(image_path), caption=image_path.stem)
160
+ for image_path in trainer.validator.save_dir.glob("val*.jpg")
161
+ ],
162
+ },
163
+ )
164
+
165
+ if trainer.best.exists():
166
+ self.run.log_artifact(
167
+ str(trainer.best),
168
+ type="model",
169
+ name=f"{self.run.name}_{trainer.args.task}.pt",
170
+ aliases=["best", f"epoch_{trainer.epoch + 1}"],
171
+ )
172
+
173
+ def on_model_save(self, trainer: BaseTrainer) -> None:
174
+ """On model save we log the model as an artifact to Weights & Biases."""
175
+ self.run.log_artifact(
176
+ str(trainer.last),
177
+ type="model",
178
+ name=f"{self.run.name}_{trainer.args.task}.pt",
179
+ aliases=["last", f"epoch_{trainer.epoch + 1}"],
180
+ )
181
+
182
+ def teardown(self, _trainer: BaseTrainer) -> None:
183
+ """On teardown, we finish the Weights & Biases run and set it to None."""
184
+ self.run.finish()
185
+ self.run = None
186
+
187
+ @property
188
+ def callbacks(
189
+ self,
190
+ ) -> Dict[str, Callable]:
191
+ """Property contains all the relevant callbacks to add to the YOLO model for the Weights & Biases logging."""
192
+ return {
193
+ "on_pretrain_routine_start": self.on_pretrain_routine_start,
194
+ "on_pretrain_routine_end": self.on_pretrain_routine_end,
195
+ "on_train_epoch_start": self.on_train_epoch_start,
196
+ "on_train_epoch_end": self.on_train_epoch_end,
197
+ "on_fit_epoch_end": self.on_fit_epoch_end,
198
+ "on_train_end": self.on_train_end,
199
+ "on_model_save": self.on_model_save,
200
+ "teardown": self.teardown,
201
+ }
202
+
203
+
204
+ def add_callbacks(
205
+ yolo: YOLO,
206
+ run_name: Optional[str] = None,
207
+ project: Optional[str] = None,
208
+ tags: Optional[List[str]] = None,
209
+ resume: Optional[str] = None,
210
+ **kwargs: Optional[Any],
211
+ ) -> YOLO:
212
+ """A YOLO model wrapper that tracks metrics, and logs models to Weights & Biases.
213
+
214
+ Args:
215
+ yolo: A YOLOv8 model that's inherited from `:class:ultralytics.yolo.engine.model.YOLO`
216
+ run_name, str: The name of the Weights & Biases run, defaults to an auto generated name if `trainer.args.name` is not defined.
217
+ project, str: The name of the Weights & Biases project, defaults to `"YOLOv8"` if `trainer.args.project` is not defined.
218
+ tags, List[str]: A list of tags to be added to the Weights & Biases run, defaults to `["YOLOv8"]`.
219
+ resume, str: Whether to resume a previous run on Weights & Biases, defaults to `None`.
220
+ **kwargs: Additional arguments to be passed to `wandb.init()`.
221
+
222
+ Usage:
223
+ ```python
224
+ from wandb.integration.yolov8 import add_callbacks as add_wandb_callbacks
225
+ model = YOLO("yolov8n.pt")
226
+ add_wandb_callbacks(model,)
227
+ model.train(data="coco128.yaml", epochs=3, imgsz=640,)
228
+ ```
229
+ """
230
+ wandb.termwarn(
231
+ """The wandb callback is currently in beta and is subject to change based on updates to `ultralytics yolov8`.
232
+ The callback is tested and supported for ultralytics v8.0.43 and above.
233
+ Please report any issues to https://github.com/wandb/wandb/issues with the tag `yolov8`.
234
+ """,
235
+ repeat=False,
236
+ )
237
+
238
+ if RANK in [-1, 0]:
239
+ wandb_logger = WandbCallback(
240
+ yolo, run_name=run_name, project=project, tags=tags, resume=resume, **kwargs
241
+ )
242
+ for event, callback_fn in wandb_logger.callbacks.items():
243
+ yolo.add_callback(event, callback_fn)
244
+ return yolo
245
+ else:
246
+ wandb.termerror(
247
+ "The RANK of the process to add the callbacks was neither 0 or -1."
248
+ "No Weights & Biases callbacks were added to this instance of the YOLO model."
249
+ )
250
+ return yolo
wandb/jupyter.py CHANGED
@@ -5,11 +5,13 @@ import re
5
5
  import shutil
6
6
  import sys
7
7
  from base64 import b64encode
8
+ from typing import Dict
8
9
 
9
10
  import requests
10
11
  from requests.compat import urljoin
11
12
 
12
13
  import wandb
14
+ import wandb.util
13
15
  from wandb.sdk.lib import filesystem
14
16
 
15
17
  try:
@@ -42,7 +44,7 @@ __IFrame = None
42
44
 
43
45
 
44
46
  def maybe_display():
45
- """Display a run if the user added cell magic and we have run"""
47
+ """Display a run if the user added cell magic and we have run."""
46
48
  if __IFrame is not None:
47
49
  return __IFrame.maybe_display()
48
50
  return False
@@ -177,10 +179,10 @@ def notebook_metadata_from_jupyter_servers_and_kernel_id():
177
179
  return None
178
180
 
179
181
 
180
- def notebook_metadata(silent):
181
- """Attempts to query jupyter for the path and name of the notebook file.
182
+ def notebook_metadata(silent) -> Dict[str, str]:
183
+ """Attempt to query jupyter for the path and name of the notebook file.
182
184
 
183
- This can handle many different jupyter environments, specifically:
185
+ This can handle different jupyter environments, specifically:
184
186
 
185
187
  1. Colab
186
188
  2. Kaggle
@@ -193,30 +195,21 @@ def notebook_metadata(silent):
193
195
  "the WANDB_NOTEBOOK_NAME environment variable to enable code saving."
194
196
  )
195
197
  try:
196
- # In colab we can request the most recent contents
198
+ jupyter_metadata = notebook_metadata_from_jupyter_servers_and_kernel_id()
199
+
200
+ # Colab:
201
+ # request the most recent contents
197
202
  ipynb = attempt_colab_load_ipynb()
198
- if ipynb:
199
- nb_name = ipynb["metadata"]["colab"]["name"]
200
- if ".ipynb" not in nb_name:
201
- nb_name += ".ipynb"
202
- ret = {
203
+ if ipynb is not None and jupyter_metadata is not None:
204
+ return {
203
205
  "root": "/content",
204
- "path": nb_name,
205
- "name": nb_name,
206
+ "path": jupyter_metadata["path"],
207
+ "name": jupyter_metadata["name"],
206
208
  }
207
209
 
208
- try:
209
- jupyter_metadata = (
210
- notebook_metadata_from_jupyter_servers_and_kernel_id()
211
- )
212
- except RuntimeError:
213
- pass
214
- else:
215
- ret["path"] = jupyter_metadata["path"]
216
- return ret
217
-
210
+ # Kaggle:
218
211
  if wandb.util._is_kaggle():
219
- # In kaggle we can request the most recent contents
212
+ # request the most recent contents
220
213
  ipynb = attempt_kaggle_load_ipynb()
221
214
  if ipynb:
222
215
  return {
@@ -225,7 +218,6 @@ def notebook_metadata(silent):
225
218
  "name": ipynb["metadata"]["name"],
226
219
  }
227
220
 
228
- jupyter_metadata = notebook_metadata_from_jupyter_servers_and_kernel_id()
229
221
  if jupyter_metadata:
230
222
  return jupyter_metadata
231
223
  if not silent:
@@ -241,8 +233,10 @@ def notebook_metadata(silent):
241
233
 
242
234
 
243
235
  def jupyter_servers_and_kernel_id():
244
- """Returns a list of servers and the current kernel_id so we can query for
245
- the name of the notebook"""
236
+ """Return a list of servers and the current kernel_id.
237
+
238
+ Used to query for the name of the notebook.
239
+ """
246
240
  try:
247
241
  import ipykernel
248
242
 
@@ -286,7 +280,7 @@ def attempt_kaggle_load_ipynb():
286
280
 
287
281
 
288
282
  def attempt_colab_login(app_url):
289
- """This renders an iframe to wandb in the hopes it posts back an api key"""
283
+ """This renders an iframe to wandb in the hopes it posts back an api key."""
290
284
  from google.colab import output
291
285
  from google.colab._message import MessageError
292
286
  from IPython import display
@@ -321,7 +315,7 @@ def attempt_colab_login(app_url):
321
315
  });
322
316
  })
323
317
  });
324
- """ # noqa: E501
318
+ """
325
319
  % app_url.replace("http:", "https:")
326
320
  )
327
321
  )
@@ -401,12 +395,14 @@ class Notebook:
401
395
  # TODO: likely only save if the code has changed
402
396
  colab_ipynb = attempt_colab_load_ipynb()
403
397
  if colab_ipynb:
404
- nb_name = (
405
- colab_ipynb.get("metadata", {})
406
- .get("colab", {})
407
- .get("name", "colab.ipynb")
408
- )
409
- if ".ipynb" not in nb_name:
398
+ try:
399
+ jupyter_metadata = (
400
+ notebook_metadata_from_jupyter_servers_and_kernel_id()
401
+ )
402
+ nb_name = jupyter_metadata["name"]
403
+ except Exception:
404
+ nb_name = "colab.ipynb"
405
+ if not nb_name.endswith(".ipynb"):
410
406
  nb_name += ".ipynb"
411
407
  with open(
412
408
  os.path.join(
@@ -434,7 +430,7 @@ class Notebook:
434
430
  return False
435
431
 
436
432
  def save_history(self):
437
- """This saves all cell executions in the current session as a new notebook"""
433
+ """This saves all cell executions in the current session as a new notebook."""
438
434
  try:
439
435
  from nbformat import v4, validator, write
440
436
  except ImportError:
@@ -1,5 +1,4 @@
1
- """
2
- Compatibility lightgbm module.
1
+ """Compatibility lightgbm module.
3
2
 
4
3
  In the future use:
5
4
  from wandb.integration.lightgbm import wandb_callback
wandb/old/settings.py CHANGED
@@ -43,7 +43,7 @@ class Settings:
43
43
  raise
44
44
 
45
45
  def set(self, section, key, value, globally=False, persist=False) -> None:
46
- """Persists settings to disk if persist = True"""
46
+ """Persist settings to disk if persist = True"""
47
47
 
48
48
  def write_setting(settings, settings_path, persist):
49
49
  if not settings.has_section(section):
@@ -109,7 +109,7 @@ class Settings:
109
109
  config_dir = os.environ.get(
110
110
  env.CONFIG_DIR, os.path.join(os.path.expanduser("~"), ".config", "wandb")
111
111
  )
112
- filesystem.mkdir_exists_ok(config_dir)
112
+ os.makedirs(config_dir, exist_ok=True)
113
113
  return os.path.join(config_dir, "settings")
114
114
 
115
115
  @staticmethod
wandb/plot/bar.py CHANGED
@@ -4,8 +4,7 @@ import wandb
4
4
 
5
5
 
6
6
  def bar(table: wandb.Table, label: str, value: str, title: Optional[str] = None):
7
- """
8
- Construct a bar plot.
7
+ """Construct a bar plot.
9
8
 
10
9
  Arguments:
11
10
  table (wandb.Table): Table of data.
@@ -13,8 +13,7 @@ def confusion_matrix(
13
13
  class_names: Optional[Sequence[str]] = None,
14
14
  title: Optional[str] = None,
15
15
  ):
16
- """
17
- Computes a multi-run confusion matrix.
16
+ """Compute a multi-run confusion matrix.
18
17
 
19
18
  Arguments:
20
19
  probs (2-d arr): Shape [n_examples, n_classes]
@@ -35,7 +34,6 @@ def confusion_matrix(
35
34
  wandb.log({'confusion_matrix': wandb.plot.confusion_matrix(probs, y_true=y_true, class_names=labels)})
36
35
  ```
37
36
  """
38
-
39
37
  np = util.get_module(
40
38
  "numpy",
41
39
  required="confusion matrix requires the numpy library, install with `pip install numpy`",
wandb/plot/histogram.py CHANGED
@@ -4,8 +4,7 @@ import wandb
4
4
 
5
5
 
6
6
  def histogram(table: wandb.Table, value: str, title: Optional[str] = None):
7
- """
8
- Construct a histogram plot.
7
+ """Construct a histogram plot.
9
8
 
10
9
  Arguments:
11
10
  table (wandb.Table): Table of data.
wandb/plot/line.py CHANGED
@@ -10,8 +10,7 @@ def line(
10
10
  stroke: Optional[str] = None,
11
11
  title: Optional[str] = None,
12
12
  ):
13
- """
14
- Construct a line plot.
13
+ """Construct a line plot.
15
14
 
16
15
  Arguments:
17
16
  table (wandb.Table): Table of data.
wandb/plot/line_series.py CHANGED
@@ -11,8 +11,7 @@ def line_series(
11
11
  title: t.Optional[str] = None,
12
12
  xname: t.Optional[str] = None,
13
13
  ):
14
- """
15
- Construct a line series plot.
14
+ """Construct a line series plot.
16
15
 
17
16
  Arguments:
18
17
  xs (array of arrays, or array): Array of arrays of x values
@@ -44,10 +43,11 @@ def line_series(
44
43
  import wandb
45
44
 
46
45
  run = wandb.init()
47
- xs = [[i for i in range(10)], [2*i for i in range(10)]]
46
+ xs = [[i for i in range(10)], [2 * i for i in range(10)]]
48
47
  ys = [[i for i in range(10)], [i**2 for i in range(10)]]
49
48
  run.log(
50
- {'line-series-plot2': wandb.plot.line_series(xs, ys, title="title", xname="step")})
49
+ {"line-series-plot2": wandb.plot.line_series(xs, ys, title="title", xname="step")}
50
+ )
51
51
  run.finish()
52
52
  ```
53
53
  """
wandb/plot/pr_curve.py CHANGED
@@ -11,32 +11,29 @@ def pr_curve(
11
11
  interp_size=21,
12
12
  title=None,
13
13
  ):
14
- """
15
- Computes the tradeoff between precision and recall for different thresholds.
16
- A high area under the curve represents both high recall and high precision,
17
- where high precision relates to a low false positive rate, and high recall
18
- relates to a low false negative rate. High scores for both show that the
19
- classifier is returning accurate results (high precision), and
20
- returning a majority of all positive results (high recall).
21
- PR curve is useful when the classes are very imbalanced.
14
+ """Compute the tradeoff between precision and recall for different thresholds.
15
+
16
+ A high area under the curve represents both high recall and high precision, where
17
+ high precision relates to a low false positive rate, and high recall relates to a
18
+ low false negative rate. High scores for both show that the classifier is returning
19
+ accurate results (high precision), and returning a majority of all positive results
20
+ (high recall). PR curve is useful when the classes are very imbalanced.
22
21
 
23
22
  Arguments:
24
- y_true (arr): true sparse labels
25
- y_probas (arr): Target scores, can either be probability estimates, confidence
26
- values, or non-thresholded measure of decisions.
27
- shape: (*y_true.shape, num_classes)
28
- labels (list): Named labels for target variable (y). Makes plots easier to
29
- read by replacing target values with corresponding index.
30
- For example labels = ['dog', 'cat', 'owl'] all 0s are
31
- replaced by 'dog', 1s by 'cat'.
23
+ y_true (arr): true sparse labels y_probas (arr): Target scores, can either be
24
+ probability estimates, confidence values, or non-thresholded measure of
25
+ decisions. shape: (*y_true.shape, num_classes)
26
+ labels (list): Named labels for target variable (y). Makes plots easier to read
27
+ by replacing target values with corresponding index. For example labels =
28
+ ['dog', 'cat', 'owl'] all 0s are replaced by 'dog', 1s by 'cat'.
32
29
  classes_to_plot (list): unique values of y_true to include in the plot
33
30
  interp_size (int): the recall values will be fixed to `interp_size` points
34
- uniform on [0, 1] and the precision will be interpolated for
35
- these recall values.
31
+ uniform on [0, 1] and the precision will be interpolated for these recall
32
+ values.
36
33
 
37
34
  Returns:
38
- Nothing. To see plots, go to your W&B run page then expand the 'media' tab
39
- under 'auto visualizations'.
35
+ Nothing. To see plots, go to your W&B run page then expand the 'media' tab under
36
+ 'auto visualizations'.
40
37
 
41
38
  Example:
42
39
  ```
wandb/plot/roc_curve.py CHANGED
@@ -6,9 +6,7 @@ from wandb.plots.utils import test_missing, test_types
6
6
  def roc_curve(
7
7
  y_true=None, y_probas=None, labels=None, classes_to_plot=None, title=None
8
8
  ):
9
- """
10
- Calculates receiver operating characteristic scores and visualizes them as the
11
- ROC curve.
9
+ """Calculate and visualize receiver operating characteristic (ROC) scores.
12
10
 
13
11
  Arguments:
14
12
  y_true (arr): true sparse labels
wandb/plot/scatter.py CHANGED
@@ -2,8 +2,7 @@ import wandb
2
2
 
3
3
 
4
4
  def scatter(table, x, y, title=None):
5
- """
6
- Construct a scatter plot.
5
+ """Construct a scatter plot.
7
6
 
8
7
  Arguments:
9
8
  table (wandb.Table): Table of data.