How can I add a batch mechanism to the input function in the Tensorflow tutorial on overcoming tf.Sparsetensor objects?

How can I add a mechanism batchto input_fnthe TensorFlow Wide and Deep Learning Tutorial , surpassing that some functions are presented as tf.Sparsetensorobjects?

I made many attempts to add tf.train.slice_input_producer, and tf.train.batchto the source code (see. Below), but could not get away until now.

I would like the global work on this input_fn to be convenient while you train and evaluate the model.

Can someone help please?

def input_fn(df):
    # Creates a dictionary mapping from each continuous feature column name (k) to
    # the values of that column stored in a constant Tensor.
    continuous_cols = {k: tf.constant(df[k].values)
                       for k in CONTINUOUS_COLUMNS}
    # Creates a dictionary mapping from each categorical feature column name (k)
    # to the values of that column stored in a tf.SparseTensor.
    categorical_cols = {k: tf.SparseTensor(indices=[[i, 0] for i in range(df[k].size)],
                                           values=df[k].values,
                                           shape=[df[k].size, 1]) for k in CATEGORICAL_COLUMNS}

    # Merges the two dictionaries into one.
    feature_cols = dict(continuous_cols.items() + categorical_cols.items())
    # Converts the label column into a constant Tensor.
    labels = tf.constant(df[LABEL_COLUMN].values)

    '''
    Changes from here: 
    '''
    features_slices, features_slices = tf.train.slice_input_producer([features_cols, labels], ...)

    features_batches, labels_batches =  tf.train.batch([features_slices, features_slices], ...)

    # Returns the feature and label batches.
    return features_batches, labels_batches
+4
source share

Source: https://habr.com/ru/post/1673234/


All Articles