Skip to content

Commit 5ebebfb

Browse files
committed
Pycaffe fixed.
1 parent 037b724 commit 5ebebfb

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

include/caffe/caffe.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "caffe/blob.hpp"
88
#include "caffe/common.hpp"
99
#include "caffe/definitions.hpp"
10+
#include "caffe/device.hpp"
1011
#include "caffe/filler.hpp"
1112
#include "caffe/greentea/greentea.hpp"
1213
#include "caffe/layer.hpp"
@@ -18,8 +19,8 @@
1819
#include "caffe/solver_factory.hpp"
1920
#include "caffe/util/benchmark.hpp"
2021
#include "caffe/util/io.hpp"
22+
#include "caffe/util/upgrade_proto.hpp"
2123
#include "caffe/vision_layers.hpp"
22-
#include "device.hpp"
2324

2425

2526

python/caffe/_caffe.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "caffe/caffe.hpp"
1818
#include "caffe/python_layer.hpp"
19+
#include "caffe/sgd_solvers.hpp"
1920

2021
// Temporary solution for numpy < 1.7 versions: old macro, no promises.
2122
// You're strongly advised to upgrade to >= 1.7.
@@ -50,7 +51,7 @@ static void CheckFile(const string& filename) {
5051
}
5152

5253
void CheckContiguousArray(PyArrayObject* arr, string name,
53-
vector<int> shape) {
54+
vector<int_tp> shape) {
5455
if (!(PyArray_FLAGS(arr) & NPY_ARRAY_C_CONTIGUOUS)) {
5556
throw std::runtime_error(name + " must be C contiguous");
5657
}
@@ -63,11 +64,12 @@ void CheckContiguousArray(PyArrayObject* arr, string name,
6364
if (PyArray_TYPE(arr) != NPY_FLOAT32) {
6465
throw std::runtime_error(name + " must be float32");
6566
}
66-
for (int i = 1; i < PyArray_NDIM(arr); ++i) {
67+
for (int_tp i = 1; i < PyArray_NDIM(arr); ++i) {
6768
if (PyArray_DIMS(arr)[i] != shape[i]) {
6869
throw std::runtime_error(
6970
"Shape dimension " + std::to_string(i) + " has wrong size ("
70-
+ std::to_string(static_cast<int>(PyArray_DIMS(arr)[i])) + " vs. "
71+
+ std::to_string(static_cast<int_tp>
72+
(PyArray_DIMS(arr)[i])) + " vs. "
7173
+ std::to_string(shape[i]) + ")");
7274
}
7375
}
@@ -134,8 +136,8 @@ void Net_SetInputArrays(Net<Dtype>* net, int index, bp::object data_obj,
134136

135137
Solver<Dtype>* GetSolverFromFile(const string& filename) {
136138
SolverParameter param;
137-
ReadProtoFromTextFileOrDie(filename, &param);
138-
return GetSolver<Dtype>(param);
139+
ReadSolverParamsFromTextFileOrDie(filename, &param);
140+
return SolverRegistry<Dtype>::CreateSolver(param);
139141
}
140142

141143
struct NdarrayConverterGenerator {
@@ -165,8 +167,8 @@ struct NdarrayCallPolicies : public bp::default_call_policies {
165167
// the shape information from the blob.
166168
void* data = PyArray_DATA(reinterpret_cast<PyArrayObject*>(result));
167169
Py_DECREF(result);
168-
const int num_axes = blob->num_axes();
169-
vector<npy_intp> dims(blob->shape().begin(), blob->shape().end());
170+
const int_tp num_axes = blob->num_axes();
171+
vector<npy_long> dims(blob->shape().begin(), blob->shape().end());
170172
PyObject *arr_obj = PyArray_SimpleNewFromData(num_axes, dims.data(),
171173
NPY_FLOAT32, data);
172174
// SetBaseObject steals a ref, so we need to INCREF.
@@ -182,9 +184,9 @@ bp::object Blob_Reshape(bp::tuple args, bp::dict kwargs) {
182184
throw std::runtime_error("Blob.reshape takes no kwargs");
183185
}
184186
Blob<Dtype>* self = bp::extract<Blob<Dtype>*>(args[0]);
185-
vector<int> shape(bp::len(args) - 1);
186-
for (int i = 1; i < bp::len(args); ++i) {
187-
shape[i - 1] = bp::extract<int>(args[i]);
187+
vector<int_tp> shape(bp::len(args) - 1);
188+
for (int_tp i = 1; i < bp::len(args); ++i) {
189+
shape[i - 1] = bp::extract<int_tp>(args[i]);
188190
}
189191
self->Reshape(shape);
190192
// We need to explicitly return None to use bp::raw_function.
@@ -197,9 +199,9 @@ bp::object BlobVec_add_blob(bp::tuple args, bp::dict kwargs) {
197199
}
198200
typedef vector<shared_ptr<Blob<Dtype> > > BlobVec;
199201
BlobVec* self = bp::extract<BlobVec*>(args[0]);
200-
vector<int> shape(bp::len(args) - 1);
201-
for (int i = 1; i < bp::len(args); ++i) {
202-
shape[i - 1] = bp::extract<int>(args[i]);
202+
vector<int_tp> shape(bp::len(args) - 1);
203+
for (int_tp i = 1; i < bp::len(args); ++i) {
204+
shape[i - 1] = bp::extract<int_tp>(args[i]);
203205
}
204206
self->push_back(shared_ptr<Blob<Dtype> >(new Blob<Dtype>(shape)));
205207
// We need to explicitly return None to use bp::raw_function.
@@ -252,14 +254,14 @@ BOOST_PYTHON_MODULE(_caffe) {
252254
"Blob", bp::no_init)
253255
.add_property("shape",
254256
bp::make_function(
255-
static_cast<const vector<int>& (Blob<Dtype>::*)() const>(
257+
static_cast<const vector<int_tp>& (Blob<Dtype>::*)() const>(
256258
&Blob<Dtype>::shape),
257259
bp::return_value_policy<bp::copy_const_reference>()))
258260
.add_property("num", &Blob<Dtype>::num)
259261
.add_property("channels", &Blob<Dtype>::channels)
260262
.add_property("height", &Blob<Dtype>::height)
261263
.add_property("width", &Blob<Dtype>::width)
262-
.add_property("count", static_cast<int (Blob<Dtype>::*)() const>(
264+
.add_property("count", static_cast<int_tp (Blob<Dtype>::*)() const>(
263265
&Blob<Dtype>::count))
264266
.def("reshape", bp::raw_function(&Blob_Reshape))
265267
.add_property("data", bp::make_function(&Blob<Dtype>::mutable_cpu_data,
@@ -322,8 +324,8 @@ BOOST_PYTHON_MODULE(_caffe) {
322324
.def(bp::vector_indexing_suite<vector<shared_ptr<Layer<Dtype> > >, true>());
323325
bp::class_<vector<string> >("StringVec")
324326
.def(bp::vector_indexing_suite<vector<string> >());
325-
bp::class_<vector<int> >("IntVec")
326-
.def(bp::vector_indexing_suite<vector<int> >());
327+
bp::class_<vector<int_tp> >("IntVec")
328+
.def(bp::vector_indexing_suite<vector<int_tp> >());
327329
bp::class_<vector<Dtype> >("DtypeVec")
328330
.def(bp::vector_indexing_suite<vector<Dtype> >());
329331
bp::class_<vector<shared_ptr<Net<Dtype> > > >("NetVec")

src/caffe/solver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Solver<Dtype>::Solver(const string& param_file, const Solver* root_solver)
4343
: net_(), callbacks_(), root_solver_(root_solver),
4444
requested_early_exit_(false) {
4545
SolverParameter param;
46-
ReadProtoFromTextFileOrDie(param_file, &param);
46+
ReadSolverParamsFromTextFileOrDie(param_file, &param);
4747
Init(param);
4848
}
4949

tools/caffe.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ int train() {
169169
"but not both.";
170170

171171
caffe::SolverParameter solver_param;
172-
caffe::ReadProtoFromTextFileOrDie(FLAGS_solver, &solver_param);
172+
caffe::ReadSolverParamsFromTextFileOrDie(FLAGS_solver, &solver_param);
173173

174174
// If the gpus flag is not provided, allow the mode and device to be set
175175
// in the solver prototxt.

0 commit comments

Comments
 (0)