@@ -19,64 +19,93 @@ static const char* model_config = "{ \
1919 \" update_thread_num\" : 2, \
2020 \" model_store_type\" : \" local\" , \
2121 \" checkpoint_dir\" : \" /home/deeprec/DeepRec/modelzoo/features/EmbeddingVariable/DIEN/result/\" , \
22- \" savedmodel_dir\" : \" /home/deeprec/DeepRec/modelzoo/features/EmbeddingVariable/DIEN/savedmodels/1658648285 /\" \
22+ \" savedmodel_dir\" : \" /home/deeprec/DeepRec/modelzoo/features/EmbeddingVariable/DIEN/savedmodels/1658740712 /\" \
2323 } " ;
2424
2525
26- ::tensorflow::eas::ArrayProto get_proto_float (std::vector<float >& cur_vector){
26+ ::tensorflow::eas::ArrayProto get_proto_float_1 (std::vector<float >& cur_vector){
2727 ::tensorflow::eas::ArrayShape array_shape;
2828 ::tensorflow::eas::ArrayDataType dtype_f =
2929 ::tensorflow::eas::ArrayDataType::DT_FLOAT;
30- int num_elem = cur_vector.size ();
31-
32- if (num_elem == 1 ){
30+
3331 array_shape.add_dim (1 );
34- // array_shape.add_dim(1);
3532 ::tensorflow::eas::ArrayProto input;
36- input.add_float_val (cur_vector.back ());
33+ input.add_float_val (( float ) cur_vector.back ());
3734 input.set_dtype (dtype_f);
3835 *(input.mutable_array_shape ()) = array_shape;
3936 return input;
40- }
37+
38+ }
39+
40+ ::tensorflow::eas::ArrayProto get_proto_float_2 (std::vector<float >& cur_vector){
41+ ::tensorflow::eas::ArrayShape array_shape;
42+ ::tensorflow::eas::ArrayDataType dtype_f =
43+ ::tensorflow::eas::ArrayDataType::DT_FLOAT;
44+ int num_elem = (int )cur_vector.size ();
4145
4246 array_shape.add_dim (1 );
43- array_shape.add_dim (cur_vector.size ());
47+ if ((int )cur_vector.size () < 0 ){
48+
49+ array_shape.add_dim (1 );
50+ ::tensorflow::eas::ArrayProto input;
51+ input.add_float_val (1.0 );
52+ input.set_dtype (dtype_f);
53+ *(input.mutable_array_shape ()) = array_shape;
54+
55+ return input;
56+ }
57+ array_shape.add_dim ((int )cur_vector.size ());
58+
4459 ::tensorflow::eas::ArrayProto input;
45- for (unsigned int tt = 0 ; tt < cur_vector.size (); ++tt)
46- {
47- input.add_float_val (cur_vector[tt]);
48- }
60+ for (int tt = 0 ; tt < ( int ) cur_vector.size (); ++tt)
61+ {
62+ input.add_float_val (( float ) cur_vector[tt]);
63+ }
4964 input.set_dtype (dtype_f);
5065 *(input.mutable_array_shape ()) = array_shape;
5166
5267 return input;
5368
5469}
5570
56- ::tensorflow::eas::ArrayProto get_proto_int (std::vector<int >& cur_vector){
71+ ::tensorflow::eas::ArrayProto get_proto_int_1 (std::vector<int >& cur_vector){
5772 ::tensorflow::eas::ArrayShape array_shape;
5873 ::tensorflow::eas::ArrayDataType dtype_i =
5974 ::tensorflow::eas::ArrayDataType::DT_INT32;
60- int num_elem = cur_vector.size ();
6175
62- if (num_elem == 1 ){
76+ array_shape.add_dim (1 );
77+ ::tensorflow::eas::ArrayProto input;
78+ input.add_int_val ((int )cur_vector.back ());
79+ input.set_dtype (dtype_i);
80+ *(input.mutable_array_shape ()) = array_shape;
81+ return input;
82+
83+ }
84+
85+ ::tensorflow::eas::ArrayProto get_proto_int_2 (std::vector<int >& cur_vector){
86+ ::tensorflow::eas::ArrayShape array_shape;
87+ ::tensorflow::eas::ArrayDataType dtype_f =
88+ ::tensorflow::eas::ArrayDataType::DT_INT32;
89+ int num_elem = (int )cur_vector.size ();
90+
91+ array_shape.add_dim (1 );
92+ if ((int )cur_vector.size () < 0 ){
93+
6394 array_shape.add_dim (1 );
64- // array_shape.add_dim(1);
6595 ::tensorflow::eas::ArrayProto input;
66- input.add_int_val (cur_vector.back ());
67- input.set_dtype (dtype_i);
68- *(input.mutable_array_shape ()) = array_shape;
69- return input;
70- }
96+ input.add_int_val (1 );
97+ input.set_dtype (dtype_f);
98+ *(input.mutable_array_shape ()) = array_shape;
7199
72- array_shape.add_dim (1 );
73- array_shape.add_dim (cur_vector.size ());
100+ return input;
101+ }
102+ array_shape.add_dim ((int )cur_vector.size ());
74103 ::tensorflow::eas::ArrayProto input;
75- for (unsigned int tt = 0 ; tt < cur_vector.size (); ++tt)
76- {
77- input.add_int_val (cur_vector[tt]);
78- }
79- input.set_dtype (dtype_i );
104+ for (int tt = 0 ; tt < ( int ) cur_vector.size (); ++tt)
105+ {
106+ input.add_int_val (( int ) cur_vector[tt]);
107+ }
108+ input.set_dtype (dtype_f );
80109 *(input.mutable_array_shape ()) = array_shape;
81110
82111 return input;
@@ -96,14 +125,14 @@ int main(int argc, char** argv) {
96125 }
97126
98127 // // ---------------------------------------prepare serving data from file--------------------------------------
99-
128+
100129 FILE *fp = nullptr ;
101130 char *line, *record;
102131 char buffer2[1024 ];
103132 char delim[] = " ," ;
104133 char next_line[] = " k" ;
105134 int cur_type = 0 ;
106-
135+
107136 // vector variables
108137 std::vector<int > cur_uids;
109138 std::vector<int > cur_mids;
@@ -137,7 +166,7 @@ int main(int argc, char** argv) {
137166 cur_type = 0 ;
138167
139168 // free memory and clear ptrs
140- for (unsigned int i = 0 ; i < temp_ptrs.size (); ++i){free (temp_ptrs[i]);}
169+ for (int i = 0 ; i < ( int ) temp_ptrs.size (); ++i){free (temp_ptrs[i]);}
141170 temp_ptrs.clear ();
142171
143172 // traverse current line
@@ -215,16 +244,19 @@ int main(int argc, char** argv) {
215244
216245 }
217246
247+ // // ---------------------------------------prepare request--------------------------------------
248+
218249
219250 // get all inputs
220- ::tensorflow::eas::ArrayProto proto_uids = get_proto_int (cur_uids);
221- ::tensorflow::eas::ArrayProto proto_mids = get_proto_int (cur_mids);
222- ::tensorflow::eas::ArrayProto proto_cats = get_proto_int (cur_cats);
223- ::tensorflow::eas::ArrayProto proto_mid_his = get_proto_int (cur_mid_his);
224- ::tensorflow::eas::ArrayProto proto_cat_his = get_proto_int (cur_cat_his);
225- ::tensorflow::eas::ArrayProto proto_mid_mask= get_proto_float (cur_mid_mask); // float
226- ::tensorflow::eas::ArrayProto proto_target = get_proto_float (cur_target); // float
227- ::tensorflow::eas::ArrayProto proto_sl = get_proto_int (cur_sl);
251+ ::tensorflow::eas::ArrayProto proto_uids = get_proto_int_1 (cur_uids); // -1
252+ ::tensorflow::eas::ArrayProto proto_mids = get_proto_int_1 (cur_mids); // -1
253+ ::tensorflow::eas::ArrayProto proto_cats = get_proto_int_1 (cur_cats); // -1
254+ ::tensorflow::eas::ArrayProto proto_mid_his = get_proto_int_2 (cur_mid_his); // -1 -1
255+ ::tensorflow::eas::ArrayProto proto_cat_his = get_proto_int_2 (cur_cat_his); // -1 -1
256+ ::tensorflow::eas::ArrayProto proto_mid_mask= get_proto_float_2 (cur_mid_mask); // float // -1 -1
257+ ::tensorflow::eas::ArrayProto proto_target = get_proto_float_2 (cur_target); // float // -1 -1
258+ ::tensorflow::eas::ArrayProto proto_sl = get_proto_int_1 (cur_sl); // -1
259+
228260
229261 // setup request
230262 ::tensorflow::eas::PredictRequest req;
@@ -244,7 +276,7 @@ int main(int argc, char** argv) {
244276 void *buffer1 = malloc (size);
245277 req.SerializeToArray (buffer1, size);
246278
247- // ---------------------------------------------- process and get feedback---------- -----------------------------------------
279+ // // -------------------------------------process and get feedback-----------------------------------------
248280 void * output = nullptr ;
249281 int output_size = 0 ;
250282 state = process (model, buffer1, size, &output, &output_size);
0 commit comments