Conversation
Introduce an Image TransformMedia implementation and wire it into the transforms registry. The new Image class accepts file paths, PIL images, numpy arrays, torch tensors, and matplotlib figures, supports optional resizing and output format validation, serializes to an image buffer, and implements column_type/build_data_record/transform (writes file with sha256-based name via safe_write). Export Image from transforms.__init__ and update tests to include an Image media factory. Also extend swanlab.vendor lazy imports to expose torch, torchvision and ensure PIL.Image submodule is imported so PIL.Image usage works with the lazy loader.
Introduce a Video media transform (GIF support) with format detection, safe file writing, sha256-based filenames, and build_data_record/transform implementations. Export Video from transforms and simplify normalize_media_input to always construct media instances (enables nested/wrapped media). Add SwanLabRun convenience methods: log_image, log_audio (with sample_rate), and log_video that normalize inputs and forward to log. Include unit tests for Video behavior and parameterized media logging; update media factories in existing tests.
Consolidate top-level run-related commands into a single cmd/run.py that generates wrappers (_make_run_cmd) for SwanLabRun methods (finish, log, log_scalar, log_text, log_image, log_audio, log_video). Remove legacy cmd/finish.py and cmd/log.py and update sdk/__init__.py and top-level swanlab/__init__.py to export the new logging APIs. Add a comprehensive type-stub swanlab/__init__.pyi describing the public API. Improve SwanLabRun lifecycle handling: register atexit and sys.excepthook handlers, add private _atexit_cleanup, _excepthook and _cleanup to centralize teardown and resource reset. Update exceptions export list and remove the example main.py. Tests updated: remove old cmd tests, rename some internal run tests, and add unit tests for the finish/exception hooks to validate the new lifecycle behavior.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly expands the SwanLab SDK's data logging capabilities by introducing dedicated support for various media types, including video, images, and audio. It also streamlines the core experiment management logic by refactoring command functions and embedding critical system hooks directly within the run object, leading to a more cohesive and resilient SDK experience. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
本次 PR 是一次重要的功能更新,引入了对 Image、Audio 和 Video 等多种媒体类型的日志记录支持。各种媒体类型的实现考虑周全,能够处理多种输入格式。代码结构方面,将命令行函数重构到 swanlab.sdk.cmd.run 模块,并将运行生命周期钩子集中到 SwanLabRun 类中,这些都是很好的改进,提升了代码的可维护性。此外,通过添加 .pyi 文件来定义公共 API,也为类型安全和开发者体验带来了提升。
我的审查意见主要包含一些关于文档一致性、类型提示准确性以及确保文档与实现同步的建议。总体而言,这是一次高质量的贡献。
Extend Image constructor type hints and docstring to accept vendor.torch.Tensor and vendor.matplotlib.figure.Figure (matplotlib figures and torch tensors). Also import matplotlib.figure under TYPE_CHECKING and add 'matplotlib.figure' to _SUBMODULE_IMPORTS in vendor/__init__ so the submodule is available for type references.
__init__.pyi定义一些主要的 API