0

I'm setting up DNN model with TensorFlow 2.0 and using AdaNet(version 0.8) to do NAS. How do I improve the accuracy of DNN model with AdaNet?

The metrics of the AdaNet-producing model, which is the combination of two different DNN subnets, is worse than the metrics of the single DNN model. I already tried tuning the parameter including max_iteration_steps and the AutoEnsembleEstimator training steps but it seemed to be not working.


from __future__ import absolute_import, division, print_function, unicode_literals

import numpy as np
import tensorflow as tf

import adanet

# load data
(x_train, y_train), (x_test, y_test) = (
    tf.keras.datasets.boston_housing.load_data())

# input_fn
def input_fn(partition):
    def _input_fn():
        feat_tensor_dict = {}
        if partition == 'train':
            x = x_train.copy()
            y = y_train.copy()
        else:
            x = x_test.copy()
            y = y_test.copy()
        for i in range(0,np.size(x,1)):
            feat_nam = ('feat'+str(i))
            feat_tensor_dict[feat_nam] = tf.convert_to_tensor(x[:,i], dtype=tf.float32)
        label_tensor = tf.convert_to_tensor(y, dtype=tf.float32)
        return (feat_tensor_dict,label_tensor)
    return _input_fn

feat_nam_lst = ['feat'+str(i) for i in range(0,np.size(x_train,1))]

feature_columns = []
for item in feat_nam_lst:
    feature_columns.append(tf.feature_column.numeric_column(item))


head = tf.estimator.RegressionHead

# Build subnetwork
dnn_estimator_1 = tf.estimator.DNNRegressor(
                feature_columns = feature_columns,
                hidden_units=[100, 500, 100])

dnn_estimator_2 = tf.estimator.DNNRegressor(
                feature_columns = feature_columns,
                hidden_units=[200, 300, 100])

# Build AdaNet
estimator = adanet.AutoEnsembleEstimator(
    head=head,
    candidate_pool=lambda config: {
        "dnn1": dnn_estimator_1,
        "dnn2":dnn_estimator_2 },
    max_iteration_steps=1000)

estimator.train(input_fn=input_fn(partition = 'train'), steps=10)
metrics = estimator.evaluate(input_fn=input_fn(partition = 'test'),steps = 1000)

best_ensemble_index_0 = 1, global_step = 10, iteration = 0, label/mean = 23.078432, loss = 65.15532, prediction/mean = 22.63752


dnn_estimator_1.train(input_fn=input_fn(partition = 'train'), steps=1000)

dnn_estimator_1.evaluate(input_fn=input_fn(partition = 'test'), steps=1000)

{'average_loss': 37.712597, 'label/mean': 23.078432, 'loss': 37.712288, 'prediction/mean': 23.500063, 'global_step': 1000}

The metrics of output of AdaNet should be better. But it turned out to be the opposite.

1 Answers1

0

It appears that you only trained AdaNet for 10 steps, whereas you trained the individual DNN for 1000 steps.

Try setting max_iteration_steps to 1000 and training for 2000 steps.

E. Zeytinci
  • 2,642
  • 1
  • 20
  • 37
Scott Yak
  • 21
  • 2