我是 tensorflow 的新手并试图学习它。尝试在 Tensorflow 2.2.0 中运行估算器 LinearClassifier。
import tensorflow as tf
print(tf.version.VERSION)
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
print (tf.executing_eagerly())
tf.executing_eagerly()
tf.compat.v1.enable_eager_execution()
path = 'train.tfrecord'
filenames = [(path + "/" + name) for name in os.listdir(path) if name.startswith("part")]
print (filenames)
Run Code Online (Sandbox Code Playgroud)
def _parse_function(example_proto):
features = {
'Age': tf.io.FixedLenFeature([], tf.string),
'EstimatedSalary': tf.io.FixedLenFeature([], tf.string),
'Purchased': tf.io.FixedLenFeature([], tf.string)
}
tf_records = tf.io.parse_single_example(example_proto, features)
features_dict = {
'Age': tf_records['Age'],
'EstimatedSalary': tf_records['EstimatedSalary']
}
return features_dict, tf_records['Purchased']
Run Code Online (Sandbox Code Playgroud)
def input_fn():
dataset = tf.data.TFRecordDataset(filenames = filenames) …Run Code Online (Sandbox Code Playgroud)