-
Notifications
You must be signed in to change notification settings - Fork 0
Examples
Saman .E edited this page Feb 27, 2023
·
1 revision
An example that demonstrates GB-CNN training on CIFAR-10, 2D-image dataset.
To find out more about the model's ability, please refer to the algorithm and corresponding paper.
import tensorflow as tf
from models.gbcnn import GBCNN
from keras.utils import np_utils
from Libs.config import get_config
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.cifar10.load_data()
def prepare_data(X, size, channels):
X = X.reshape(X.shape[0], size, size, channels)
X = X.astype("float32")
return X/255.
X_train = prepare_data(x_train, 32, 3)
X_test = prepare_data(x_test, 32, 3)
Y_train = np_utils.to_categorical(y_train, 10)
Y_test = np_utils.to_categorical(y_test, 10)
params = {'config': Namespace(seed=111,
boosting_epoch=40,
boosting_eta=1e-3,
save_records=False,
additive_epoch=100,
batch=128,
units=20,
additive_eta=1e-3,
patience=2)}
model = GBCNN(config=get_config())
model.set_params(**params)
print(model.get_params())
model.fit(X_train, Y_train, X_test, Y_test)
# Note that the X_test and Y_test in the fit are optional. If None, the validation report will not be generated.
To train on the tabular dataset, the Deep-GBNN model should be introduced.
from models.gbdnn import GBDNNClassifier
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
X, y = make_classification(n_informative=16, n_classes=10, n_samples=5000)
x_train, x_test, y_train, y_test = train_test_split(X, y)
model = GBDNNClassifier(config=get_config())
model.set_params(**params)
model.fit(x_train, y_train)
print(f"GB-DNN SCORE:{model.score(x_test, y_test)}")
The models are developed so that the different hyperparameter optimization such as grid search can be easily applied through the config. To know more about the hyperparameters, you can just check the config.