Exemplo n.º 1
0
 virtual void LoadModel(utils::IStream &fi){
   utils::Check(fi.Read(&param_, sizeof(LayerParam)) != 0,
                "BiasLayer: LoadModel invalid model file");
   bias_.LoadBinary(fi);
   gbias_.Resize(bias_.shape_);
   gbias_ = 0.0f;
 }
Exemplo n.º 2
0
 virtual void LoadModel(utils::IStream &fi) {
   utils::Check(fi.Read(&param_, sizeof(LayerParam)) != 0,
                 "FullConnectLayer:LoadModel invalid model file");    
   wmat_.LoadBinary(fi);
   bias_.LoadBinary(fi);
   // setup gradient weight
   gwmat_.Resize(wmat_.shape_);
   gbias_.Resize(bias_.shape_);
   gwmat_ = 0.0f; gbias_ = 0.0f;
 }
Exemplo n.º 3
0
 /*!
  * \brief load model from stream
  * \param fi input stream
  * \param calc_num_feature whether call InitTrainer with calc_num_feature
  */
 inline void LoadModel(utils::IStream &fi,  // NOLINT(*)
                       bool calc_num_feature = true) {
   utils::Check(fi.Read(&mparam, sizeof(ModelParam)) != 0,
                "BoostLearner: wrong model format");
   {
     // backward compatibility code for compatible with old model type
     // for new model, Read(&name_obj_) is suffice
     uint64_t len;
     utils::Check(fi.Read(&len, sizeof(len)) != 0, "BoostLearner: wrong model format");
     if (len >= std::numeric_limits<unsigned>::max()) {
       int gap;
       utils::Check(fi.Read(&gap, sizeof(gap)) != 0, "BoostLearner: wrong model format");
       len = len >> static_cast<uint64_t>(32UL);
     }
     if (len != 0) {
       name_obj_.resize(len);
       utils::Check(fi.Read(&name_obj_[0], len) != 0, "BoostLearner: wrong model format");
     }
   }
  /*!
   * \brief load from binary stream
   * \param fs input file stream
   * \param silent whether print information during loading
   * \param fname file name, used to print message
   */
  inline void LoadBinary(utils::IStream &fs, bool silent = false, const char *fname = NULL) {
    int magic;
    utils::Check(fs.Read(&magic, sizeof(magic)) != 0, "invalid input file format");
    utils::Check(magic == kMagic, "invalid format,magic number mismatch");

    info.LoadBinary(fs);
    FMatrixS::LoadBinary(fs, &row_ptr_, &row_data_);
    fmat.LoadColAccess(fs);

    if (!silent) {
      printf("%lux%lu matrix with %lu entries is loaded",
             info.num_row(), info.num_col(), row_data_.size());
      if (fname != NULL) {
        printf(" from %s\n", fname);
      } else {
        printf("\n");
      }
      if (info.group_ptr.size() != 0) {
        printf("data contains %u groups\n", (unsigned)info.group_ptr.size()-1);
      }
    }
  }
Exemplo n.º 5
0
 // load model from file
 inline void LoadModel(utils::IStream &fi) { // NOLINT(*)
   XGBOOST_STATIC_ASSERT(sizeof(Param) % sizeof(uint64_t) == 0)
   utils::Assert(fi.Read(&param, sizeof(Param)) != 0, "Load LinearBooster");
   fi.Read(&weight);
 }
Exemplo n.º 6
0
 // load model from file
 inline void LoadModel(utils::IStream &fi) {
   utils::Assert(fi.Read(&param, sizeof(Param)) != 0, "Load LinearBooster");
   fi.Read(&weight);
 }
Exemplo n.º 7
0
 inline static int ReadInt(utils::IStream &fi) {
   unsigned char buf[4];
   utils::Assert(fi.Read(buf, sizeof(buf)) == 1, "Failed to read an int\n");
   return int(buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3]);
 }