Commit bfe183460c8b145ac4d3f46a856c49b20ac64490
1 parent
95cd60aa
Update stream::train
This needs to be a little more complicated. Retain the project pattern done by Streams during partial projects by using a timeVarying transform to collect the output template sets (grouped as they are at the end of the partial stream).
Showing
1 changed file
with
29 additions
and
0 deletions
openbr/plugins/stream.cpp
| @@ -1014,7 +1014,27 @@ public: | @@ -1014,7 +1014,27 @@ public: | ||
| 1014 | 1014 | ||
| 1015 | }; | 1015 | }; |
| 1016 | 1016 | ||
| 1017 | +// Semi-functional, doesn't do anything productive outside of stream::train | ||
| 1018 | +class CollectSets : public TimeVaryingTransform | ||
| 1019 | +{ | ||
| 1020 | + Q_OBJECT | ||
| 1021 | +public: | ||
| 1022 | + CollectSets() : TimeVaryingTransform(false, false) {} | ||
| 1023 | + | ||
| 1024 | + QList<TemplateList> sets; | ||
| 1017 | 1025 | ||
| 1026 | + void projectUpdate(const TemplateList &src, TemplateList &dst) | ||
| 1027 | + { | ||
| 1028 | + (void) dst; | ||
| 1029 | + sets.append(src); | ||
| 1030 | + } | ||
| 1031 | + | ||
| 1032 | + void train(const TemplateList & data) | ||
| 1033 | + { | ||
| 1034 | + (void) data; | ||
| 1035 | + } | ||
| 1036 | + | ||
| 1037 | +}; | ||
| 1018 | 1038 | ||
| 1019 | class DirectStreamTransform : public CompositeTransform | 1039 | class DirectStreamTransform : public CompositeTransform |
| 1020 | { | 1040 | { |
| @@ -1036,16 +1056,24 @@ public: | @@ -1036,16 +1056,24 @@ public: | ||
| 1036 | if (end_idx == 0) | 1056 | if (end_idx == 0) |
| 1037 | return; | 1057 | return; |
| 1038 | 1058 | ||
| 1059 | + CollectSets collector; | ||
| 1060 | + | ||
| 1039 | // Set transforms to the start, up to end_idx | 1061 | // Set transforms to the start, up to end_idx |
| 1040 | QList<Transform *> backup = this->transforms; | 1062 | QList<Transform *> backup = this->transforms; |
| 1041 | transforms = backup.mid(0,end_idx); | 1063 | transforms = backup.mid(0,end_idx); |
| 1064 | + // We use collector to retain the project structure at the end of the | ||
| 1065 | + // truncated stream. | ||
| 1066 | + transforms.append(&collector); | ||
| 1042 | 1067 | ||
| 1043 | // Reinitialize, we now act as a shorter stream. | 1068 | // Reinitialize, we now act as a shorter stream. |
| 1044 | init(); | 1069 | init(); |
| 1045 | 1070 | ||
| 1071 | + QList<TemplateList> output; | ||
| 1046 | for (int i=0; i < data.size(); i++) { | 1072 | for (int i=0; i < data.size(); i++) { |
| 1047 | projectUpdate(data[i], data[i]); | 1073 | projectUpdate(data[i], data[i]); |
| 1074 | + output.append(collector.sets); | ||
| 1048 | } | 1075 | } |
| 1076 | + data = output; | ||
| 1049 | transforms = backup; | 1077 | transforms = backup; |
| 1050 | } | 1078 | } |
| 1051 | 1079 | ||
| @@ -1062,6 +1090,7 @@ public: | @@ -1062,6 +1090,7 @@ public: | ||
| 1062 | QList<TemplateList> copy = data; | 1090 | QList<TemplateList> copy = data; |
| 1063 | // Project from the start to the trainable stage. | 1091 | // Project from the start to the trainable stage. |
| 1064 | subProject(copy,i); | 1092 | subProject(copy,i); |
| 1093 | + | ||
| 1065 | transforms[i]->train(copy); | 1094 | transforms[i]->train(copy); |
| 1066 | } | 1095 | } |
| 1067 | } | 1096 | } |