Commit 1f64c307 authored by 赵威's avatar 赵威

try predict

parent 04916ba2
...@@ -29,7 +29,7 @@ def main(): ...@@ -29,7 +29,7 @@ def main():
all_features = build_features(df) all_features = build_features(df)
params = {"feature_columns": all_features, "hidden_units": [32], "learning_rate": 0.1} params = {"feature_columns": all_features, "hidden_units": [64, 32], "learning_rate": 0.1}
model_path = str(Path("~/data/model_tmp/").expanduser()) model_path = str(Path("~/data/model_tmp/").expanduser())
if os.path.exists(model_path): if os.path.exists(model_path):
shutil.rmtree(model_path) shutil.rmtree(model_path)
...@@ -48,10 +48,7 @@ def main(): ...@@ -48,10 +48,7 @@ def main():
for i in range(10): for i in range(10):
test_300 = test_df.sample(300) test_300 = test_df.sample(300)
time_1 = timeit.default_timer()
model_predict(test_300, predict_fn) model_predict(test_300, predict_fn)
total_1 = (timeit.default_timer() - time_1)
print("prediction cost {:.5f} s".format(total_1))
total_time = (time.time() - time_begin) / 60 total_time = (time.time() - time_begin) / 60
print("cost {:.2f} mins at {}".format(total_time, datetime.now())) print("cost {:.2f} mins at {}".format(total_time, datetime.now()))
......
...@@ -2,6 +2,7 @@ import tensorflow as tf ...@@ -2,6 +2,7 @@ import tensorflow as tf
from tensorflow import feature_column as fc from tensorflow import feature_column as fc
from tensorflow.python.estimator.canned import head as head_lib from tensorflow.python.estimator.canned import head as head_lib
from tensorflow.python.ops.losses import losses from tensorflow.python.ops.losses import losses
import timeit
def build_deep_layer(net, params): def build_deep_layer(net, params):
...@@ -90,7 +91,6 @@ def _bytes_feature(value): ...@@ -90,7 +91,6 @@ def _bytes_feature(value):
def model_predict(inputs, predict_fn): def model_predict(inputs, predict_fn):
int_columns = [ int_columns = [
"active_type", "active_days", "card_id", "is_pure_author", "is_have_reply", "is_have_pure_reply", "content_level", "active_type", "active_days", "card_id", "is_pure_author", "is_have_reply", "is_have_pure_reply", "content_level",
"topic_num", "favor_num", "vote_num" "topic_num", "favor_num", "vote_num"
...@@ -110,6 +110,9 @@ def model_predict(inputs, predict_fn): ...@@ -110,6 +110,9 @@ def model_predict(inputs, predict_fn):
features[col] = _bytes_feature(str(value).encode(encoding="utf-8")) features[col] = _bytes_feature(str(value).encode(encoding="utf-8"))
example = tf.train.Example(features=tf.train.Features(feature=features)) example = tf.train.Example(features=tf.train.Features(feature=features))
examples.append(example.SerializeToString()) examples.append(example.SerializeToString())
time_1 = timeit.default_timer()
predictions = predict_fn({"examples": examples}) predictions = predict_fn({"examples": examples})
total_1 = (timeit.default_timer() - time_1)
print("prediction cost {:.5f} s".format(total_1))
# print(predictions) # print(predictions)
return predictions return predictions
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment