Skip to content

Conversation

Copy link

Copilot AI commented Dec 15, 2025

Implements a Python library for rasterizing vector data (points, lines, polygons) with a direct training API for machine learning workflows.

Core Components

  • Rasterizer - Converts vector geometries to raster grids with rasterize_points(), rasterize_lines(), rasterize_polygon(), and batch_rasterize()
  • Trainer - High-level training API with three usage modes:
    • prepare_training_data() - Rasterize and normalize for any ML framework
    • train() - Train models directly with prepared data
    • train_from_raw_data() - One-step pipeline from raw vectors to trained model

Usage

from rasterizer import Trainer
import numpy as np

trainer = Trainer(width=256, height=256)

# Option 1: Prepare data for any framework (TensorFlow/PyTorch/sklearn)
data = [{'type': 'points', 'data': np.array([[10, 20], [30, 40]]), 'radius': 2.0}]
X_train, y_train = trainer.prepare_training_data(data, labels)

# Option 2: One-step training
trainer.train_from_raw_data(data, labels, model=your_model, epochs=10)

Implementation Details

  • Handles degenerate cases (identical coordinates, collinear vertices) by centering at image midpoint
  • Framework-agnostic: accepts any model with fit() method
  • Normalization with proper zero-division handling using EPSILON = 1e-8
  • Returns shape (batch, height, width, 1) for CNN compatibility

Testing

20 unit tests covering core functionality and edge cases, bilingual documentation with examples.

Original prompt

这个库是否有提供一个api供我直接使用训练我的数据?


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits December 15, 2025 03:25
Implements a comprehensive API for training data with rasterization:
- Core Rasterizer class for vector-to-raster conversion
- Trainer class with direct training API
- Support for points, lines, and polygons
- Batch processing capabilities
- Complete documentation and examples
- Unit tests with 100% pass rate

Co-authored-by: macintoshwan <69745614+macintoshwan@users.noreply.github.com>
- Fix division by zero in point/polygon normalization when all coordinates are identical
- Replace unusable load_model with set_model for better UX
- Add tests for edge cases (identical coordinates, degenerate polygons)
- Update documentation to reflect API changes

Co-authored-by: macintoshwan <69745614+macintoshwan@users.noreply.github.com>
- Add EPSILON constant for consistent floating-point comparisons
- Improve normalization to handle edge cases (all zeros, all same value)
- Add detailed comments explaining history handling for different ML frameworks
- All tests passing, no security vulnerabilities found

Co-authored-by: macintoshwan <69745614+macintoshwan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add API for direct data training integration Add training API for vector data rasterization Dec 15, 2025
Copilot AI requested a review from macintoshwan December 15, 2025 03:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants