-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathludwig_training_with_image.py
More file actions
36 lines (27 loc) · 1002 Bytes
/
ludwig_training_with_image.py
File metadata and controls
36 lines (27 loc) · 1002 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import pandas as pd
from ludwig.api import LudwigModel
# read csv file into pandas dataframe
df = pd.read_csv('data.csv')
# define Ludwig configuration
config = {
'input_features': [
# numerical feature called my_feature
{'name': 'my_feature', 'type': 'numerical'},
# categorical feature called my_category
{'name': 'my_category', 'type': 'category'},
# image feature called my_image with torchvision encoder resnet-18
{'name': 'my_image', 'type': 'image', 'encoder': 'resnet-18'} # Commentary: requires modification
],
'output_features': [
# categorical feature called target
{'name': 'target', 'type': 'category'}
],
# train for 50 epochs with learning rate 0.0002
'training': {'epochs': 50, 'learning_rate': 0.0002}
}
# create a Ludwig model
model = LudwigModel(config)
# train the model
train_stats = model.train(data_df=df)
# make predictions on the test set
predictions = model.predict(data_df=df)