Tensorflow: train_and_evaluate always producing loss 0
I have a project using a canned estimator in Tensorflow and trying to produce train_and_evaluate method.
estimator = tf.estimator.DNNClassifier(
feature_columns=my_feature_columns,
hidden_units=hidden_units,
model_dir=model_dir,
optimizer=tf.train.ProximalAdagradOptimizer(learning_rate=0.01,l1_regularization_strength=0.001))
Every time that I see the console output it shows that the loss is always zero.
INFO:tensorflow:loss = 2.896826e-06, step = 875
INFO:tensorflow:global_step/sec: 5.96785
INFO:tensorflow:loss = 1.9453131e-05, step = 975 (16.756 sec)
INFO:tensorflow:global_step/sec: 7.2834
INFO:tensorflow:loss = 8.6957414e-05, step = 1075 (13.730 sec)
INFO:tensorflow:global_step/sec: 7.36042
INFO:tensorflow:loss = 0.0004585028, step = 1175 (13.586 sec)
INFO:tensorflow:global_step/sec: 7.38419
INFO:tensorflow:loss = 0.0012249642, step = 1275 (13.542 sec)
INFO:tensorflow:global_step/sec: 7.3658
INFO:tensorflow:loss = 0.002194246, step = 1375 (13.576 sec)
INFO:tensorflow:global_step/sec: 7.33054
INFO:tensorflow:loss = 0.0031063582, step = 1475 (13.641 sec)
This happened since I change my input_fn (I used to load my CSV into a pandas Dataframe and work from there, however my total Dataset is over 10GB (800x1500000 in dimensions), and every time that I used to save the model, the model folder size used to be crazy large (over 200GB), so I decided to use iterators instead (I found this input function in a tutorial somewhere and it works well):
def input_fn_train(filenames,
num_epochs=None,
shuffle=True,
skip_header_lines=0,
batch_size=200,
modeTrainEval=True):
filename_dataset = tf.data.Dataset.from_tensor_slices(filenames)
if shuffle:
filename_dataset = filename_dataset.shuffle(len(filenames))
dataset = filename_dataset.flat_map(lambda filename: tf.data.TextLineDataset(filename).skip(skip_header_lines))
dataset = dataset.map(parse_csv)
if shuffle:
dataset = dataset.shuffle(buffer_size=batch_size * 10)
dataset = dataset.repeat(num_epochs)
dataset = dataset.batch(batch_size)
iterator = dataset.make_one_shot_iterator()
features = iterator.get_next()
features, labels = features, features.pop(LABEL_COLUMN)
if not modeTrainEval:
return features, None
return features, labels
Unfortunately, this change caused my loss being always be zero, and as a consequence the predictions are terribly bad (50% accuracy), and I can't find the reason why.
(github link with sample dataset and my code)
python tensorflow deep-learning tensorflow-estimator
add a comment |
I have a project using a canned estimator in Tensorflow and trying to produce train_and_evaluate method.
estimator = tf.estimator.DNNClassifier(
feature_columns=my_feature_columns,
hidden_units=hidden_units,
model_dir=model_dir,
optimizer=tf.train.ProximalAdagradOptimizer(learning_rate=0.01,l1_regularization_strength=0.001))
Every time that I see the console output it shows that the loss is always zero.
INFO:tensorflow:loss = 2.896826e-06, step = 875
INFO:tensorflow:global_step/sec: 5.96785
INFO:tensorflow:loss = 1.9453131e-05, step = 975 (16.756 sec)
INFO:tensorflow:global_step/sec: 7.2834
INFO:tensorflow:loss = 8.6957414e-05, step = 1075 (13.730 sec)
INFO:tensorflow:global_step/sec: 7.36042
INFO:tensorflow:loss = 0.0004585028, step = 1175 (13.586 sec)
INFO:tensorflow:global_step/sec: 7.38419
INFO:tensorflow:loss = 0.0012249642, step = 1275 (13.542 sec)
INFO:tensorflow:global_step/sec: 7.3658
INFO:tensorflow:loss = 0.002194246, step = 1375 (13.576 sec)
INFO:tensorflow:global_step/sec: 7.33054
INFO:tensorflow:loss = 0.0031063582, step = 1475 (13.641 sec)
This happened since I change my input_fn (I used to load my CSV into a pandas Dataframe and work from there, however my total Dataset is over 10GB (800x1500000 in dimensions), and every time that I used to save the model, the model folder size used to be crazy large (over 200GB), so I decided to use iterators instead (I found this input function in a tutorial somewhere and it works well):
def input_fn_train(filenames,
num_epochs=None,
shuffle=True,
skip_header_lines=0,
batch_size=200,
modeTrainEval=True):
filename_dataset = tf.data.Dataset.from_tensor_slices(filenames)
if shuffle:
filename_dataset = filename_dataset.shuffle(len(filenames))
dataset = filename_dataset.flat_map(lambda filename: tf.data.TextLineDataset(filename).skip(skip_header_lines))
dataset = dataset.map(parse_csv)
if shuffle:
dataset = dataset.shuffle(buffer_size=batch_size * 10)
dataset = dataset.repeat(num_epochs)
dataset = dataset.batch(batch_size)
iterator = dataset.make_one_shot_iterator()
features = iterator.get_next()
features, labels = features, features.pop(LABEL_COLUMN)
if not modeTrainEval:
return features, None
return features, labels
Unfortunately, this change caused my loss being always be zero, and as a consequence the predictions are terribly bad (50% accuracy), and I can't find the reason why.
(github link with sample dataset and my code)
python tensorflow deep-learning tensorflow-estimator
add a comment |
I have a project using a canned estimator in Tensorflow and trying to produce train_and_evaluate method.
estimator = tf.estimator.DNNClassifier(
feature_columns=my_feature_columns,
hidden_units=hidden_units,
model_dir=model_dir,
optimizer=tf.train.ProximalAdagradOptimizer(learning_rate=0.01,l1_regularization_strength=0.001))
Every time that I see the console output it shows that the loss is always zero.
INFO:tensorflow:loss = 2.896826e-06, step = 875
INFO:tensorflow:global_step/sec: 5.96785
INFO:tensorflow:loss = 1.9453131e-05, step = 975 (16.756 sec)
INFO:tensorflow:global_step/sec: 7.2834
INFO:tensorflow:loss = 8.6957414e-05, step = 1075 (13.730 sec)
INFO:tensorflow:global_step/sec: 7.36042
INFO:tensorflow:loss = 0.0004585028, step = 1175 (13.586 sec)
INFO:tensorflow:global_step/sec: 7.38419
INFO:tensorflow:loss = 0.0012249642, step = 1275 (13.542 sec)
INFO:tensorflow:global_step/sec: 7.3658
INFO:tensorflow:loss = 0.002194246, step = 1375 (13.576 sec)
INFO:tensorflow:global_step/sec: 7.33054
INFO:tensorflow:loss = 0.0031063582, step = 1475 (13.641 sec)
This happened since I change my input_fn (I used to load my CSV into a pandas Dataframe and work from there, however my total Dataset is over 10GB (800x1500000 in dimensions), and every time that I used to save the model, the model folder size used to be crazy large (over 200GB), so I decided to use iterators instead (I found this input function in a tutorial somewhere and it works well):
def input_fn_train(filenames,
num_epochs=None,
shuffle=True,
skip_header_lines=0,
batch_size=200,
modeTrainEval=True):
filename_dataset = tf.data.Dataset.from_tensor_slices(filenames)
if shuffle:
filename_dataset = filename_dataset.shuffle(len(filenames))
dataset = filename_dataset.flat_map(lambda filename: tf.data.TextLineDataset(filename).skip(skip_header_lines))
dataset = dataset.map(parse_csv)
if shuffle:
dataset = dataset.shuffle(buffer_size=batch_size * 10)
dataset = dataset.repeat(num_epochs)
dataset = dataset.batch(batch_size)
iterator = dataset.make_one_shot_iterator()
features = iterator.get_next()
features, labels = features, features.pop(LABEL_COLUMN)
if not modeTrainEval:
return features, None
return features, labels
Unfortunately, this change caused my loss being always be zero, and as a consequence the predictions are terribly bad (50% accuracy), and I can't find the reason why.
(github link with sample dataset and my code)
python tensorflow deep-learning tensorflow-estimator
I have a project using a canned estimator in Tensorflow and trying to produce train_and_evaluate method.
estimator = tf.estimator.DNNClassifier(
feature_columns=my_feature_columns,
hidden_units=hidden_units,
model_dir=model_dir,
optimizer=tf.train.ProximalAdagradOptimizer(learning_rate=0.01,l1_regularization_strength=0.001))
Every time that I see the console output it shows that the loss is always zero.
INFO:tensorflow:loss = 2.896826e-06, step = 875
INFO:tensorflow:global_step/sec: 5.96785
INFO:tensorflow:loss = 1.9453131e-05, step = 975 (16.756 sec)
INFO:tensorflow:global_step/sec: 7.2834
INFO:tensorflow:loss = 8.6957414e-05, step = 1075 (13.730 sec)
INFO:tensorflow:global_step/sec: 7.36042
INFO:tensorflow:loss = 0.0004585028, step = 1175 (13.586 sec)
INFO:tensorflow:global_step/sec: 7.38419
INFO:tensorflow:loss = 0.0012249642, step = 1275 (13.542 sec)
INFO:tensorflow:global_step/sec: 7.3658
INFO:tensorflow:loss = 0.002194246, step = 1375 (13.576 sec)
INFO:tensorflow:global_step/sec: 7.33054
INFO:tensorflow:loss = 0.0031063582, step = 1475 (13.641 sec)
This happened since I change my input_fn (I used to load my CSV into a pandas Dataframe and work from there, however my total Dataset is over 10GB (800x1500000 in dimensions), and every time that I used to save the model, the model folder size used to be crazy large (over 200GB), so I decided to use iterators instead (I found this input function in a tutorial somewhere and it works well):
def input_fn_train(filenames,
num_epochs=None,
shuffle=True,
skip_header_lines=0,
batch_size=200,
modeTrainEval=True):
filename_dataset = tf.data.Dataset.from_tensor_slices(filenames)
if shuffle:
filename_dataset = filename_dataset.shuffle(len(filenames))
dataset = filename_dataset.flat_map(lambda filename: tf.data.TextLineDataset(filename).skip(skip_header_lines))
dataset = dataset.map(parse_csv)
if shuffle:
dataset = dataset.shuffle(buffer_size=batch_size * 10)
dataset = dataset.repeat(num_epochs)
dataset = dataset.batch(batch_size)
iterator = dataset.make_one_shot_iterator()
features = iterator.get_next()
features, labels = features, features.pop(LABEL_COLUMN)
if not modeTrainEval:
return features, None
return features, labels
Unfortunately, this change caused my loss being always be zero, and as a consequence the predictions are terribly bad (50% accuracy), and I can't find the reason why.
(github link with sample dataset and my code)
python tensorflow deep-learning tensorflow-estimator
python tensorflow deep-learning tensorflow-estimator
asked Nov 14 '18 at 0:41
zeelloszeellos
326
326
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291545%2ftensorflow-train-and-evaluate-always-producing-loss-0%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291545%2ftensorflow-train-and-evaluate-always-producing-loss-0%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown