{ std::ifstream file(weightsFilePath, std::ios_base::binary); assert(file.good()); std::string line; file.ignore(4); char buf[2]; file.read(buf, 1); if ((int)(unsigned char)buf[0] == 1) { file.ignore(11); } else if ((int)(unsigned char)buf[0] == 2) { file.ignore(15); } }
| 424 | // } |
| 425 | //} |
| 426 | std::vector<float> LoadWeights(const std::string weightsFilePath) |
| 427 | { |
| 428 | assert(fileExists(weightsFilePath)); |
| 429 | std::cout << "Loading pre-trained weights..." << std::endl; |
| 430 | std::ifstream file(weightsFilePath, std::ios_base::binary); |
| 431 | assert(file.good()); |
| 432 | std::string line; |
| 433 | file.ignore(4); |
| 434 | char buf[2]; |
| 435 | file.read(buf, 1); |
| 436 | if ((int)(unsigned char)buf[0] == 1) |
| 437 | { |
| 438 | file.ignore(11); |
| 439 | } |
| 440 | else if ((int)(unsigned char)buf[0] == 2) |
| 441 | { |
| 442 | file.ignore(15); |
| 443 | } |
| 444 | else |
| 445 | { |
| 446 | std::cout << "Invalid network type" << std::endl; |
| 447 | assert(0); |
| 448 | } |
| 449 | |
| 450 | std::vector<float> weights; |
| 451 | char* floatWeight = new char[4]; |
| 452 | while (!file.eof()) |
| 453 | { |
| 454 | file.read(floatWeight, 4); |
| 455 | assert(file.gcount() == 4); |
| 456 | weights.push_back(*reinterpret_cast<float*>(floatWeight)); |
| 457 | if (file.peek() == std::istream::traits_type::eof()) break; |
| 458 | } |
| 459 | std::cout << "Loading complete!" << std::endl; |
| 460 | delete[] floatWeight; |
| 461 | |
| 462 | // std::cout << "Total Number of weights read : " << weights.size() << std::endl; |
| 463 | return weights; |
| 464 | } |
| 465 | |
| 466 | std::string dimsToString(const nvinfer1::Dims d) |
| 467 | { |
no test coverage detected