| 455 | |
| 456 | template<typename Dtype> |
| 457 | vector<int> DataTransformer<Dtype>::InferBlobShape(const Datum& datum) { |
| 458 | if (datum.encoded()) { |
| 459 | #ifdef USE_OPENCV |
| 460 | CHECK(!(param_.force_color() && param_.force_gray())) |
| 461 | << "cannot set both force_color and force_gray"; |
| 462 | cv::Mat cv_img; |
| 463 | if (param_.force_color() || param_.force_gray()) { |
| 464 | // If force_color then decode in color otherwise decode in gray. |
| 465 | cv_img = DecodeDatumToCVMat(datum, param_.force_color()); |
| 466 | } else { |
| 467 | cv_img = DecodeDatumToCVMatNative(datum); |
| 468 | } |
| 469 | // InferBlobShape using the cv::image. |
| 470 | return InferBlobShape(cv_img); |
| 471 | #else |
| 472 | LOG(FATAL) << "Encoded datum requires OpenCV; compile with USE_OPENCV."; |
| 473 | #endif // USE_OPENCV |
| 474 | } |
| 475 | const int crop_size = param_.crop_size(); |
| 476 | const int datum_channels = datum.channels(); |
| 477 | const int datum_height = datum.height(); |
| 478 | const int datum_width = datum.width(); |
| 479 | // Check dimensions. |
| 480 | CHECK_GT(datum_channels, 0); |
| 481 | CHECK_GE(datum_height, crop_size); |
| 482 | CHECK_GE(datum_width, crop_size); |
| 483 | // Build BlobShape. |
| 484 | vector<int> shape(4); |
| 485 | shape[0] = 1; |
| 486 | shape[1] = datum_channels; |
| 487 | shape[2] = (crop_size)? crop_size: datum_height; |
| 488 | shape[3] = (crop_size)? crop_size: datum_width; |
| 489 | return shape; |
| 490 | } |
| 491 | |
| 492 | template<typename Dtype> |
| 493 | vector<int> DataTransformer<Dtype>::InferBlobShape( |
no test coverage detected