Skip to main content

NWF for computer vision: ConvVAE, ResNet encoders, Split-CIFAR incremental learning, continual learning on images.

Project description

nwf-vision

PyPI version Python 3.9+ Tests License: MIT

NWF for Computer Vision

nwf-vision provides encoders and examples for incremental learning, OOD detection, and active learning on images. Built on top of nwf-core, it uses its indices, metrics, and calibrators.

Features

  • ConvVAEEncoder — convolutional VAE for images (CIFAR 32x32, MNIST)
  • PretrainedVisionEncoder — ResNet18/34 with (z, sigma) head for NWF charges
  • Split-CIFAR-10 example — incremental classification without catastrophic forgetting
  • Support for NHWC and NCHW input layouts

Installation

pip install nwf-vision

Requires: nwf-core, torch, torchvision.


Encoders

ConvVAEEncoder

Convolutional VAE producing (z, sigma) for NWF charges. Suitable for small images (32x32).

from nwf.vision import ConvVAEEncoder
import numpy as np

enc = ConvVAEEncoder(input_shape=(3, 32, 32), latent_dim=64)
enc.fit(train_images, epochs=20)
z, sigma = enc.encode(images[:10])
  • input_shape — (C, H, W), e.g. (3, 32, 32) for CIFAR
  • latent_dim — dimension of z
  • hidden_dims — encoder channel sizes (default: 32, 64, 128)
  • fit(train_data, epochs, batch_size, lr) — train VAE
  • encode(x) — returns (z, sigma) as numpy arrays; accepts NHWC or NCHW

PretrainedVisionEncoder

ResNet backbone from torchvision with a head producing (z, sigma).

from nwf.vision import PretrainedVisionEncoder

enc = PretrainedVisionEncoder(
    backbone="resnet18",
    latent_dim=64,
    pretrained=True,
    trainable=False,
)
enc.fit(images, epochs=5)
z, sigma = enc.encode(images)
  • backbone — "resnet18" or "resnet34"
  • pretrained — use ImageNet weights
  • trainable — fine-tune backbone or freeze it
  • Input: (N, 3, 224, 224) for ImageNet-style models

Example: Split-CIFAR-10

Incremental learning: 5 tasks, 2 classes each. Train ConvVAE once, add charges per task.

pip install nwf-core nwf-vision
python examples/split_cifar.py --epochs 5 --n-tasks 5

The example demonstrates adding new classes without retraining the encoder and without catastrophic forgetting.


Planned

  • OOD detection example (CIFAR-10 vs SVHN)
  • Active learning example (uncertainty-based sampling)
  • ood_detection.py, active_learning.py in examples/

License

MIT


nwf-vision (Русский)

NWF для компьютерного зрения

nwf-vision предоставляет энкодеры и примеры для инкрементального обучения, OOD-детекции и активного обучения на изображениях.

Компоненты

  • ConvVAEEncoder — свёрточный VAE для изображений (CIFAR 32x32, MNIST); выход (z, sigma)
  • PretrainedVisionEncoder — ResNet18/34 с головой для (z, sigma); предобученные веса
  • Split-CIFAR-10 — пример инкрементальной классификации без катастрофического забывания

Установка

pip install nwf-vision

Пример

from nwf.vision import ConvVAEEncoder
from nwf import Charge, Field

enc = ConvVAEEncoder(input_shape=(3, 32, 32), latent_dim=64)
enc.fit(images, epochs=10)
z, sigma = enc.encode(images[:5])

field = Field()
for i in range(5):
    field.add(Charge(z=z[i], sigma=sigma[i]), labels=[labels[i]])

Лицензия

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nwf_vision-0.1.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nwf_vision-0.1.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file nwf_vision-0.1.1.tar.gz.

File metadata

  • Download URL: nwf_vision-0.1.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for nwf_vision-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e2414eda6696e06f6a029712a30396fa0939fe5de7149fdbd2ac27cce2d56d92
MD5 d47aaae1a6f6986ea4c3dedb99770dd7
BLAKE2b-256 dc30626eb9cca319f0992b1dc8391d5c5de3bab5428dd1a6aefeb9014f2265a4

See more details on using hashes here.

File details

Details for the file nwf_vision-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: nwf_vision-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for nwf_vision-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 49c40d6d7d48f187e032fcf37fe41c7dcbf4313bf247008362c5edfef40c0e94
MD5 4bf4695ed1afaee8843da2d05aca6552
BLAKE2b-256 aa7e90a451a68c7bcc6c0dd4c3b1aff54a439f35460253840c3708916d9b01c2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page