-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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