• 大小: 8.37MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-19
  • 语言: 其他
  • 标签: caffe  

资源简介

caffe-master官方.zip

资源截图

代码片段和文件信息

//
// This script converts the CIFAR dataset to the leveldb format used
// by caffe to perform classification.
// Usage:
//    convert_cifar_data input_folder output_db_file
// The CIFAR dataset could be downloaded at
//    http://www.cs.toronto.edu/~kriz/cifar.html

#include   // NOLINT(readability/streams)
#include 

#include “boost/scoped_ptr.hpp“
#include “glog/logging.h“
#include “google/protobuf/text_format.h“
#include “stdint.h“

#include “caffe/proto/caffe.pb.h“
#include “caffe/util/db.hpp“
#include “caffe/util/format.hpp“

using caffe::Datum;
using boost::scoped_ptr;
using std::string;
namespace db = caffe::db;

const int kCIFARSize = 32;
const int kCIFARImageNBytes = 3072;
const int kCIFARBatchSize = 10000;
const int kCIFARTrainBatches = 5;

void read_image(std::ifstream* file int* label char* buffer) {
  char label_char;
  file->read(&label_char 1);
  *label = label_char;
  file->read(buffer kCIFARImageNBytes);
  return;
}

void convert_dataset(const string& input_folder const string& output_folder
    const string& db_type) {
  scoped_ptr train_db(db::GetDB(db_type));
  train_db->Open(output_folder + “/cifar10_train_“ + db_type db::NEW);
  scoped_ptr txn(train_db->NewTransaction());
  // Data buffer
  int label;
  char str_buffer[kCIFARImageNBytes];
  Datum datum;
  datum.set_channels(3);
  datum.set_height(kCIFARSize);
  datum.set_width(kCIFARSize);

  LOG(INFO) << “Writing Training data“;
  for (int fileid = 0; fileid < kCIFARTrainBatches; ++fileid) {
    // Open files
    LOG(INFO) << “Training Batch “ << fileid + 1;
    string batchFileName = input_folder + “/data_batch_“
      + caffe::format_int(fileid+1) + “.bin“;
    std::ifstream data_file(batchFileName.c_str()
        std::ios::in | std::ios::binary);
    CHECK(data_file) << “Unable to open train file #“ << fileid + 1;
    for (int itemid = 0; itemid < kCIFARBatchSize; ++itemid) {
      read_image(&data_file &label str_buffer);
      datum.set_label(label);
      datum.set_data(str_buffer kCIFARImageNBytes);
      string out;
      CHECK(datum.SerializeToString(&out));
      txn->Put(caffe::format_int(fileid * kCIFARBatchSize + itemid 5) out);
    }
  }
  txn->Commit();
  train_db->Close();

  LOG(INFO) << “Writing Testing data“;
  scoped_ptr test_db(db::GetDB(db_type));
  test_db->Open(output_folder + “/cifar10_test_“ + db_type db::NEW);
  txn.reset(test_db->NewTransaction());
  // Open files
  std::ifstream data_file((input_folder + “/test_batch.bin“).c_str()
      std::ios::in | std::ios::binary);
  CHECK(data_file) << “Unable to open test file.“;
  for (int itemid = 0; itemid < kCIFARBatchSize; ++itemid) {
    read_image(&data_file &label str_buffer);
    datum.set_label(label);
    datum.set_data(str_buffer kCIFARImageNBytes);
    string out;
    CHECK(datum.SerializeToString(&out));
    txn->Put(caffe::format_int(itemid 5) out);
  }
  txn->Commit();
  test_db->Close();
}

int main(int argc char** ar

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2016-10-27 20:11  caffe-master\
     文件      101863  2016-10-27 20:11  caffe-master\.Doxyfile
     文件        1164  2016-10-27 20:11  caffe-master\.gitignore
     文件        1938  2016-10-27 20:11  caffe-master\.travis.yml
     文件        3012  2016-10-27 20:11  caffe-master\CMakeLists.txt
     文件        1917  2016-10-27 20:11  caffe-master\CONTRIBUTING.md
     文件         620  2016-10-27 20:11  caffe-master\CONTRIBUTORS.md
     文件         210  2016-10-27 20:11  caffe-master\INSTALL.md
     文件        2095  2016-10-27 20:11  caffe-master\LICENSE
     文件       23840  2016-10-27 20:11  caffe-master\Makefile
     文件        4283  2016-10-27 20:11  caffe-master\Makefile.config.example
     文件        2102  2016-10-27 20:11  caffe-master\README.md
     文件        1180  2016-10-27 20:11  caffe-master\caffe.cloc
     目录           0  2016-10-27 20:11  caffe-master\cmake\
     文件        4373  2016-10-27 20:11  caffe-master\cmake\ConfigGen.cmake
     文件       11312  2016-10-27 20:11  caffe-master\cmake\Cuda.cmake
     文件        5755  2016-10-27 20:11  caffe-master\cmake\Dependencies.cmake
     目录           0  2016-10-27 20:11  caffe-master\cmake\External\
     文件        1939  2016-10-27 20:11  caffe-master\cmake\External\gflags.cmake
     文件        1719  2016-10-27 20:11  caffe-master\cmake\External\glog.cmake
     文件        1764  2016-10-27 20:11  caffe-master\cmake\Misc.cmake
     目录           0  2016-10-27 20:11  caffe-master\cmake\Modules\
     文件        1684  2016-10-27 20:11  caffe-master\cmake\Modules\FindAtlas.cmake
     文件        1545  2016-10-27 20:11  caffe-master\cmake\Modules\FindGFlags.cmake
     文件        1451  2016-10-27 20:11  caffe-master\cmake\Modules\FindGlog.cmake
     文件        6723  2016-10-27 20:11  caffe-master\cmake\Modules\FindLAPACK.cmake
     文件        1119  2016-10-27 20:11  caffe-master\cmake\Modules\FindLMDB.cmake
     文件        1728  2016-10-27 20:11  caffe-master\cmake\Modules\FindLevelDB.cmake
     文件        3360  2016-10-27 20:11  caffe-master\cmake\Modules\FindMKL.cmake
     文件        1749  2016-10-27 20:11  caffe-master\cmake\Modules\FindMatlabMex.cmake
     文件        2333  2016-10-27 20:11  caffe-master\cmake\Modules\FindNumPy.cmake
............此处省略671个文件信息

评论

共有 条评论