@@ -19,64 +19,93 @@ static const char* model_config = "{ \
19
19
\" update_thread_num\" : 2, \
20
20
\" model_store_type\" : \" local\" , \
21
21
\" 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 /\" \
23
23
} " ;
24
24
25
25
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){
27
27
::tensorflow::eas::ArrayShape array_shape;
28
28
::tensorflow::eas::ArrayDataType dtype_f =
29
29
::tensorflow::eas::ArrayDataType::DT_FLOAT;
30
- int num_elem = cur_vector.size ();
31
-
32
- if (num_elem == 1 ){
30
+
33
31
array_shape.add_dim (1 );
34
- // array_shape.add_dim(1);
35
32
::tensorflow::eas::ArrayProto input;
36
- input.add_float_val (cur_vector.back ());
33
+ input.add_float_val (( float ) cur_vector.back ());
37
34
input.set_dtype (dtype_f);
38
35
*(input.mutable_array_shape ()) = array_shape;
39
36
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 ();
41
45
42
46
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
+
44
59
::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
+ }
49
64
input.set_dtype (dtype_f);
50
65
*(input.mutable_array_shape ()) = array_shape;
51
66
52
67
return input;
53
68
54
69
}
55
70
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){
57
72
::tensorflow::eas::ArrayShape array_shape;
58
73
::tensorflow::eas::ArrayDataType dtype_i =
59
74
::tensorflow::eas::ArrayDataType::DT_INT32;
60
- int num_elem = cur_vector.size ();
61
75
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
+
63
94
array_shape.add_dim (1 );
64
- // array_shape.add_dim(1);
65
95
::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;
71
99
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 ());
74
103
::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 );
80
109
*(input.mutable_array_shape ()) = array_shape;
81
110
82
111
return input;
@@ -96,14 +125,14 @@ int main(int argc, char** argv) {
96
125
}
97
126
98
127
// // ---------------------------------------prepare serving data from file--------------------------------------
99
-
128
+
100
129
FILE *fp = nullptr ;
101
130
char *line, *record;
102
131
char buffer2[1024 ];
103
132
char delim[] = " ," ;
104
133
char next_line[] = " k" ;
105
134
int cur_type = 0 ;
106
-
135
+
107
136
// vector variables
108
137
std::vector<int > cur_uids;
109
138
std::vector<int > cur_mids;
@@ -137,7 +166,7 @@ int main(int argc, char** argv) {
137
166
cur_type = 0 ;
138
167
139
168
// 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]);}
141
170
temp_ptrs.clear ();
142
171
143
172
// traverse current line
@@ -215,16 +244,19 @@ int main(int argc, char** argv) {
215
244
216
245
}
217
246
247
+ // // ---------------------------------------prepare request--------------------------------------
248
+
218
249
219
250
// 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
+
228
260
229
261
// setup request
230
262
::tensorflow::eas::PredictRequest req;
@@ -244,7 +276,7 @@ int main(int argc, char** argv) {
244
276
void *buffer1 = malloc (size);
245
277
req.SerializeToArray (buffer1, size);
246
278
247
- // ---------------------------------------------- process and get feedback---------- -----------------------------------------
279
+ // // -------------------------------------process and get feedback-----------------------------------------
248
280
void * output = nullptr ;
249
281
int output_size = 0 ;
250
282
state = process (model, buffer1, size, &output, &output_size);
0 commit comments