Skip to content

Commit b7121cf

Browse files
committed
fix
1 parent ecb1f3f commit b7121cf

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

demo/deep_model/freeze_graph.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@
2323
python ../../python/freeze_graph.py \
2424
--checkpoint_dir='./checkpoint' \
2525
--graph_pb='./model/predict_graph.pb' \
26-
--output_node_names='forward/logit/add' \
26+
--output_node_names='pctr' \
2727
--output_dir='./model'

python/deep_model.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ def forward(self, sparse_id, sparse_val):
5858

5959
#dim = net.get_shape().as_list()[1]
6060
dim = self.hidden_layer[-1]
61-
self.weight = tf.Variable(tf.truncated_normal([dim, 1], stddev=0.1), name='weight_out')
62-
self.bias = tf.Variable(tf.truncated_normal([1], stddev=0.1), name='bias_out')
61+
self.weight = tf.Variable(tf.truncated_normal([dim, 2], stddev=0.1), name='weight_out')
62+
self.bias = tf.Variable(tf.truncated_normal([2], stddev=0.1), name='bias_out')
6363
with tf.variable_scope("logit"):
6464
logits = tf.matmul(net, self.weight) + self.bias
6565

python/predict_model.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828

2929
# define loss
3030
logits, all_parameter = model.forward(sparse_id, sparse_val)
31-
train_label = tf.to_int64(label)
32-
cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=train_label, name='cross_entropy')
31+
softmax = tf.nn.softmax(logits, name='pctr')
3332

3433
# save graph
3534
with tf.Session() as sess:

python/train.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@
6060
train_label = tf.to_int64(train_label)
6161
cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=train_label, name='cross_entropy')
6262
loss = tf.reduce_mean(cross_entropy, name='loss')
63-
auc, _ = tf.metrics.auc(predictions=logits, labels=train_label)
64-
cost = tf.reduce_mean(loss, name='cost')
6563

6664
# define optimizer
6765
print("Optimization algorithm: {}".format(FLAGS.optimizer))
@@ -82,7 +80,7 @@
8280
exit(1)
8381

8482
global_step = tf.Variable(0, name='global_step', trainable=False)
85-
train_op = optimizer.minimize(cost, global_step=global_step)
83+
train_op = optimizer.minimize(loss, global_step=global_step)
8684

8785
# to eval
8886
tf.get_variable_scope().reuse_variables()
@@ -92,7 +90,6 @@
9290
valid_label = tf.to_int64(valid_label)
9391
valid_cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=valid_logits, labels=valid_label)
9492
valid_loss = tf.reduce_mean(valid_cross_entropy)
95-
valid_auc, _ = tf.metrics.auc(predictions=valid_logits, labels=valid_label)
9693

9794
# saver
9895
checkpoint_file = FLAGS.checkpoint_dir + "/model.checkpoint"
@@ -113,11 +110,11 @@
113110
threads = tf.train.start_queue_runners(coord=coord, sess=sess)
114111
try:
115112
while not coord.should_stop():
116-
_, step, train_loss_val, train_auc_val = sess.run([train_op, global_step, loss, auc])
113+
_, step, train_loss_val = sess.run([train_op, global_step, loss])
117114
if step % FLAGS.steps_to_validate == 0:
118-
valid_loss_val, valid_auc_val = sess.run([valid_loss, valid_auc])
119-
print("Step: {}, train loss: {}, train auc: {}, valid loss: {}, valid auc: {}".format(
120-
step, train_loss_val, train_auc_val, valid_loss_val, valid_auc_val))
115+
valid_loss_val = sess.run([valid_loss])
116+
print("Step: {}, train loss: {}, valid loss: {}".format(
117+
step, train_loss_val, valid_loss_val))
121118
except tf.errors.OutOfRangeError:
122119
print("training done")
123120
finally:

src/deep_model.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,21 @@ int main(int argc, char* argv[]) {
136136
std::vector<tensorflow::Tensor> outputs;
137137

138138
// Run the session, evaluating our "predict/add" operation from the graph
139-
status = session->Run(inputs, {"forward/logit/add"}, {}, &outputs);
139+
status = session->Run(inputs, {"pctr"}, {}, &outputs);
140140
if (!status.ok()) {
141141
std::cerr << status.ToString() << std::endl;
142142
return 1;
143143
} else {
144144
std::cout << "Run session successfully" << std::endl;
145145
}
146146

147-
// Grab the first output (we only evaluated one graph node: "predict/add")
147+
// Grab the first output (we only evaluated one graph node: "pctr")
148148
// and convert the node to a scalar representation.
149-
auto output_softmax = outputs[0].scalar<float>();
149+
auto pctr = outputs[0].tensor<float, 2>()(0, 1);
150150

151151
// Print the results
152152
std::cout << outputs[0].DebugString() << std::endl;
153-
std::cout << "output value: " << output_softmax() << std::endl;
153+
std::cout << "output value: " << pctr << std::endl;
154154

155155
// Free any resources used by the session
156156
session->Close();

0 commit comments

Comments
 (0)