Commit 2b19cefa authored by 赵威's avatar 赵威

add timer

parent 831ec291
......@@ -14,7 +14,7 @@ from sklearn.model_selection import train_test_split
from models.esmm.fe import (click_feature_engineering, device_feature_engineering, diary_feature_engineering,
get_device_dict_from_redis, get_diary_dict_from_redis, join_features, read_csv_data)
from models.esmm.input_fn import build_features, esmm_input_fn
from models.esmm.model import (esmm_model_fn, model_export, model_predict, model_predict2)
from models.esmm.model import esmm_model_fn, model_export, model_predict2
# tf.compat.v1.enable_eager_execution()
......
......@@ -123,33 +123,6 @@ def model_predict2(device_id, diary_ids, device_dict, diary_dict, predict_fn):
features[col] = _bytes_feature(str(value).encode(encoding="utf-8"))
example = tf.train.Example(features=tf.train.Features(feature=features))
examples.append(example.SerializeToString())
predictions = predict_fn({"examples": examples})
total_1 = (timeit.default_timer() - time_1)
print("prediction cost {:.5f}s".format(total_1))
return predictions
def model_predict(inputs, predict_fn):
time_1 = timeit.default_timer()
int_columns = [
"active_type", "active_days", "card_id", "is_pure_author", "is_have_reply", "is_have_pure_reply", "content_level",
"topic_num", "favor_num", "vote_num"
]
float_columns = ["one_ctr", "three_ctr", "seven_ctr", "fifteen_ctr"]
examples = []
for index, row in inputs.iterrows():
features = {}
for col, value in row.iteritems():
if col in ["click_label", "conversion_label"]:
pass
elif col in int_columns:
features[col] = _int64_feature(int(value))
elif col in float_columns:
features[col] = _float_feature(float(value))
else:
features[col] = _bytes_feature(str(value).encode(encoding="utf-8"))
example = tf.train.Example(features=tf.train.Features(feature=features))
examples.append(example.SerializeToString())
total_1 = (timeit.default_timer() - time_1)
print("make example cost {:.5f}s".format(total_1))
......@@ -157,6 +130,37 @@ def model_predict(inputs, predict_fn):
predictions = predict_fn({"examples": examples})
total_1 = (timeit.default_timer() - time_1)
print("prediction cost {:.5f}s".format(total_1))
# print(predictions)
# TODO get the diary ids
return predictions
# def model_predict(inputs, predict_fn):
# time_1 = timeit.default_timer()
# int_columns = [
# "active_type", "active_days", "card_id", "is_pure_author", "is_have_reply", "is_have_pure_reply", "content_level",
# "topic_num", "favor_num", "vote_num"
# ]
# float_columns = ["one_ctr", "three_ctr", "seven_ctr", "fifteen_ctr"]
# examples = []
# for index, row in inputs.iterrows():
# features = {}
# for col, value in row.iteritems():
# if col in ["click_label", "conversion_label"]:
# pass
# elif col in int_columns:
# features[col] = _int64_feature(int(value))
# elif col in float_columns:
# features[col] = _float_feature(float(value))
# else:
# features[col] = _bytes_feature(str(value).encode(encoding="utf-8"))
# example = tf.train.Example(features=tf.train.Features(feature=features))
# examples.append(example.SerializeToString())
# total_1 = (timeit.default_timer() - time_1)
# print("make example cost {:.5f}s".format(total_1))
# time_1 = timeit.default_timer()
# predictions = predict_fn({"examples": examples})
# total_1 = (timeit.default_timer() - time_1)
# print("prediction cost {:.5f}s".format(total_1))
# # print(predictions)
# # TODO get the diary ids
# 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