Quick Start

In carefree-learn, it's easy to train and serialize a model for all tasks.

Training

Machine Learning ๐Ÿ“ˆ

import cflearn
from cfdata.tabular import TabularDataset
x, y = TabularDataset.iris().xy
m = cflearn.api.fit_ml(x, y, carefree=True)
# Predict logits
inference_data = cflearn.ml.MLInferenceData(x, y)
m.predict(inference_data)[cflearn.PREDICTIONS_KEY]
# Evaluate performance
cflearn.ml.evaluate(inference_data, pipelines=m, metrics=["acc", "auc"])

This yields:

================================================================================================================================
| metrics | acc | auc |
--------------------------------------------------------------------------------------------------------------------------------
| | mean | std | score | mean | std | score |
--------------------------------------------------------------------------------------------------------------------------------
| fcnn | 0.980000 | 0.000000 | 0.980000 | 0.998933 | 0.000000 | 0.998933 |
================================================================================================================================

Computer Vision ๐Ÿ–ผ๏ธ

import cflearn
data = cflearn.cv.MNISTData(transform="to_tensor")
m = cflearn.api.resnet18_gray(10)
# m.fit(data, cuda=0) # If CUDA available
# m.fit(data) # If not

Serializing

Saving

carefree-learn pipelines can be saved easily, into a .zip file (for both ml & cv tasks) !

m.save("model") # a `model.zip` file will be created

It's worth mentioning that carefree-learn supports a two-stage style serializing:

  1. A _logs folder (with timestamps as its subfolders) will be created after training.
--- _logs
|-- 2021-08-08_16-00-24-175005
|-- checkpoints
|-- configs.json
|-- metrics.txt
...
|-- 2021-08-08_17-25-21-803661
|-- checkpoints
|-- configs.json
|-- metrics.txt
...
  1. carefree-learn could therefore 'pack' the corresponding (timestamp) folder into a .zip file.
cflearn.api.pack("_logs/2021-08-08_17-25-21-803661")
note

This pack API is a 'unified' API, which means you can use it to serialize either Machine Learning pipelines or Computer Vision pipelines!

Loading

Of course, loading carefree-learn pipelines are easy as well!

m = cflearn.api.load("/path/to/your/zip/file")
note
  • This is also a 'unified' API.
  • .zip file exported from either save API or pack API can be loaded in this way.
Last updated on