| 315 | |
| 316 | template <typename Dtype> |
| 317 | bool Net<Dtype>::StateMeetsRule(const NetState& state, |
| 318 | const NetStateRule& rule, const string& layer_name) { |
| 319 | // Check whether the rule is broken due to phase. |
| 320 | if (rule.has_phase()) { |
| 321 | if (rule.phase() != state.phase()) { |
| 322 | LOG_IF(INFO, Caffe::root_solver()) |
| 323 | << "The NetState phase (" << state.phase() |
| 324 | << ") differed from the phase (" << rule.phase() |
| 325 | << ") specified by a rule in layer " << layer_name; |
| 326 | return false; |
| 327 | } |
| 328 | } |
| 329 | // Check whether the rule is broken due to min level. |
| 330 | if (rule.has_min_level()) { |
| 331 | if (state.level() < rule.min_level()) { |
| 332 | LOG_IF(INFO, Caffe::root_solver()) |
| 333 | << "The NetState level (" << state.level() |
| 334 | << ") is above the min_level (" << rule.min_level() |
| 335 | << ") specified by a rule in layer " << layer_name; |
| 336 | return false; |
| 337 | } |
| 338 | } |
| 339 | // Check whether the rule is broken due to max level. |
| 340 | if (rule.has_max_level()) { |
| 341 | if (state.level() > rule.max_level()) { |
| 342 | LOG_IF(INFO, Caffe::root_solver()) |
| 343 | << "The NetState level (" << state.level() |
| 344 | << ") is above the max_level (" << rule.max_level() |
| 345 | << ") specified by a rule in layer " << layer_name; |
| 346 | return false; |
| 347 | } |
| 348 | } |
| 349 | // Check whether the rule is broken due to stage. The NetState must |
| 350 | // contain ALL of the rule's stages to meet it. |
| 351 | for (int i = 0; i < rule.stage_size(); ++i) { |
| 352 | // Check that the NetState contains the rule's ith stage. |
| 353 | bool has_stage = false; |
| 354 | for (int j = 0; !has_stage && j < state.stage_size(); ++j) { |
| 355 | if (rule.stage(i) == state.stage(j)) { has_stage = true; } |
| 356 | } |
| 357 | if (!has_stage) { |
| 358 | LOG_IF(INFO, Caffe::root_solver()) |
| 359 | << "The NetState did not contain stage '" << rule.stage(i) |
| 360 | << "' specified by a rule in layer " << layer_name; |
| 361 | return false; |
| 362 | } |
| 363 | } |
| 364 | // Check whether the rule is broken due to not_stage. The NetState must |
| 365 | // contain NONE of the rule's not_stages to meet it. |
| 366 | for (int i = 0; i < rule.not_stage_size(); ++i) { |
| 367 | // Check that the NetState contains the rule's ith not_stage. |
| 368 | bool has_stage = false; |
| 369 | for (int j = 0; !has_stage && j < state.stage_size(); ++j) { |
| 370 | if (rule.not_stage(i) == state.stage(j)) { has_stage = true; } |
| 371 | } |
| 372 | if (has_stage) { |
| 373 | LOG_IF(INFO, Caffe::root_solver()) |
| 374 | << "The NetState contained a not_stage '" << rule.not_stage(i) |