@@ -37,10 +37,22 @@ inline double GetCurrentMs() {
37
37
return 1e+3 * time.tv_sec + 1e-3 * time.tv_usec ;
38
38
}
39
39
40
+ // This function just give dummy data for recognize_digits model.
41
+ size_t DummyData (std::vector<paddle::framework::LoDTensor>* out) {
42
+ paddle::framework::LoDTensor input;
43
+ SetupTensor<float >(&input, {1 , 1 , 28 , 28 }, -1 .f , 1 .f );
44
+ out->emplace_back (input);
45
+ return 1 ;
46
+ }
47
+
40
48
// Load the input word index data from file and save into LodTensor.
41
49
// Return the size of words.
42
50
size_t LoadData (std::vector<paddle::framework::LoDTensor>* out,
43
51
const std::string& filename) {
52
+ if (filename.empty ()) {
53
+ return DummyData (out);
54
+ }
55
+
44
56
size_t sz = 0 ;
45
57
std::fstream fin (filename);
46
58
std::string line;
@@ -130,9 +142,12 @@ void ThreadRunInfer(
130
142
}
131
143
132
144
TEST (inference, nlp) {
133
- if (FLAGS_modelpath.empty () || FLAGS_datafile.empty ()) {
134
- LOG (FATAL) << " Usage: ./example --modelpath=path/to/your/model "
135
- << " --datafile=path/to/your/data" ;
145
+ if (FLAGS_modelpath.empty ()) {
146
+ LOG (FATAL) << " Usage: ./example --modelpath=path/to/your/model" ;
147
+ }
148
+ if (FLAGS_datafile.empty ()) {
149
+ LOG (WARNING) << " Not data file provided, will use dummy data!"
150
+ << " Note: if you use nlp model, please provide data file." ;
136
151
}
137
152
LOG (INFO) << " Model Path: " << FLAGS_modelpath;
138
153
LOG (INFO) << " Data File: " << FLAGS_datafile;
0 commit comments