Skip to content

Instantly share code, notes, and snippets.

@metamath1
Created February 12, 2024 15:55
Show Gist options
  • Save metamath1/0dc3893e11a887cdd2544372d9e46852 to your computer and use it in GitHub Desktop.
Save metamath1/0dc3893e11a887cdd2544372d9e46852 to your computer and use it in GitHub Desktop.
Example of handling MNIST as a 784-dimensional vector input in ludwig.ai
import os
import logging
from ludwig.api import LudwigModel
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
config = {
'preprocessing': {
'split': {
'type': 'fixed',
'column': 'split'
}
},
'input_features': [
{
'name': 'image',
'type': 'vector',
'encoder': {
'type': 'dense',
'fc_layers': [
{'output_size': 64},
{'output_size': 32}
]
}
}
],
'output_features': [
{'name': 'label', 'type': 'category'}
],
'trainer': {'epochs': 1, 'batch_size': 64, 'eval_batch_size': 128}
}
model = LudwigModel(
config = config,
gpus=0,
logging_level=logging.INFO
)
# mnist_vector.parquet scheme
# image label split
# 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0
# 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0
# 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0
# 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0
# 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ... 0 0
# ...
train_stats, _, _ = model.train(dataset='./mnist_vector.parquet')
model_ecd = model.model
print(model_ecd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment