| 446 | |
| 447 | template <typename Dtype> |
| 448 | void Blob<Dtype>::FromProto(const BlobProto& proto, bool reshape) { |
| 449 | if (reshape) { |
| 450 | vector<int> shape; |
| 451 | if (proto.has_num() || proto.has_channels() || |
| 452 | proto.has_height() || proto.has_width()) { |
| 453 | // Using deprecated 4D Blob dimensions -- |
| 454 | // shape is (num, channels, height, width). |
| 455 | shape.resize(4); |
| 456 | shape[0] = proto.num(); |
| 457 | shape[1] = proto.channels(); |
| 458 | shape[2] = proto.height(); |
| 459 | shape[3] = proto.width(); |
| 460 | } else { |
| 461 | shape.resize(proto.shape().dim_size()); |
| 462 | for (int i = 0; i < proto.shape().dim_size(); ++i) { |
| 463 | shape[i] = proto.shape().dim(i); |
| 464 | } |
| 465 | } |
| 466 | Reshape(shape); |
| 467 | } else { |
| 468 | CHECK(ShapeEquals(proto)) << "shape mismatch (reshape not set)"; |
| 469 | } |
| 470 | // copy data |
| 471 | Dtype* data_vec = mutable_cpu_data(); |
| 472 | if (proto.double_data_size() > 0) { |
| 473 | CHECK_EQ(count_, proto.double_data_size()); |
| 474 | for (int i = 0; i < count_; ++i) { |
| 475 | data_vec[i] = proto.double_data(i); |
| 476 | } |
| 477 | } else { |
| 478 | CHECK_EQ(count_, proto.data_size()); |
| 479 | for (int i = 0; i < count_; ++i) { |
| 480 | data_vec[i] = proto.data(i); |
| 481 | } |
| 482 | } |
| 483 | if (proto.double_diff_size() > 0) { |
| 484 | CHECK_EQ(count_, proto.double_diff_size()); |
| 485 | Dtype* diff_vec = mutable_cpu_diff(); |
| 486 | for (int i = 0; i < count_; ++i) { |
| 487 | diff_vec[i] = proto.double_diff(i); |
| 488 | } |
| 489 | } else if (proto.diff_size() > 0) { |
| 490 | CHECK_EQ(count_, proto.diff_size()); |
| 491 | Dtype* diff_vec = mutable_cpu_diff(); |
| 492 | for (int i = 0; i < count_; ++i) { |
| 493 | diff_vec[i] = proto.diff(i); |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | |
| 498 | template <> |
| 499 | void Blob<double>::ToProto(BlobProto* proto, bool write_diff) const { |
no test coverage detected