Skip to main content

Pytorch extension for OpenML python

Pytorch extension for openml-python API. This library provides a simple way to run your Pytorch models on OpenML tasks.

For a more native experience, PyTorch itself provides OpenML integrations for some tasks. You can find more information here.

Installation Instructions:

pip install openml-pytorch

PyPi link https://pypi.org/project/openml-pytorch/

Set the API key for OpenML from the command line:

openml configure apikey <your API key>

Usage

Import openML libraries

import torch.nn
import torch.optim

import openml_pytorch.config
import openml
import logging

from openml_pytorch.trainer import OpenMLTrainerModule
from openml_pytorch.trainer import OpenMLDataModule
from torchvision.transforms import Compose, Resize, ToPILImage, ToTensor, Lambda
import torchvision
from openml_pytorch.trainer import convert_to_rgb

Create a pytorch model and get a task from openML

model = torchvision.models.efficientnet_b0(num_classes=200)
# Download the OpenML task for tiniest imagenet
task = openml.tasks.get_task(362128)

Download the task from openML and define Data and Trainer configuration

transform = Compose(
    [
        ToPILImage(),  # Convert tensor to PIL Image to ensure PIL Image operations can be applied.
        Lambda(
            convert_to_rgb
        ),  # Convert PIL Image to RGB if it's not already.
        Resize(
            (64, 64)
        ),  # Resize the image.
        ToTensor(),  # Convert the PIL Image back to a tensor.
    ]
)
data_module = OpenMLDataModule(
    type_of_data="image",
    file_dir="datasets",
    filename_col="image_path",
    target_mode="categorical",
    target_column="label",
    batch_size = 64,
    transform=transform
)
trainer = OpenMLTrainerModule(
    data_module=data_module,
    verbose = True,
    epoch_count = 1,
)
openml_pytorch.config.trainer = trainer

Run the model on the task

run = openml.runs.run_model_on_task(model, task, avoid_duplicate_runs=False)
run.publish()
print('URL for run: %s/run/%d' % (openml.config.server, run.run_id))

Note: The input layer of the network should be compatible with OpenML data output shape. Please check examples for more information.

Additionally, if you want to publish the run with onnx file, then you must call openml_pytorch.add_onnx_to_run() immediately before run.publish().

run = openml_pytorch.add_onnx_to_run(run)

Download files

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

Source Distribution

openml_pytorch-0.1.0.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

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

openml_pytorch-0.1.0-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file openml_pytorch-0.1.0.tar.gz.

File metadata

  • Download URL: openml_pytorch-0.1.0.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Darwin/24.1.0

File hashes

Hashes for openml_pytorch-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fafe5421c9f566d1d4e61af6ae53214e42cbbac71ff42cbea7e6740a409116de
MD5 3778b7bc9ddc7f64e19821deb331ec3b
BLAKE2b-256 213d67332f17adf89bad39756bee57215b56d832231b8e252782020505486bde

See more details on using hashes here.

File details

Details for the file openml_pytorch-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: openml_pytorch-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 30.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 Darwin/24.1.0

File hashes

Hashes for openml_pytorch-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0901ba17259c8ea9a143bcd32d891eec0384ef5487139543a1e5c134128e9a1f
MD5 d7d6581a821457b2ac8185ef3b8569bc
BLAKE2b-256 636f5f85ae611888565515b82cd84bdba0b6d7aba57b7934548134a165a656b8

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

This release

0.1.0 This release

2 files

0.0.5

1 file

0.0.4

1 file

0.0.3

1 file

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page