| 148 | } |
| 149 | |
| 150 | void Net_SetInputArrays(Net<Dtype>* net, bp::object data_obj, |
| 151 | bp::object labels_obj) { |
| 152 | // check that this network has an input MemoryDataLayer |
| 153 | shared_ptr<MemoryDataLayer<Dtype> > md_layer = |
| 154 | boost::dynamic_pointer_cast<MemoryDataLayer<Dtype> >(net->layers()[0]); |
| 155 | if (!md_layer) { |
| 156 | throw std::runtime_error("set_input_arrays may only be called if the" |
| 157 | " first layer is a MemoryDataLayer"); |
| 158 | } |
| 159 | |
| 160 | // check that we were passed appropriately-sized contiguous memory |
| 161 | PyArrayObject* data_arr = |
| 162 | reinterpret_cast<PyArrayObject*>(data_obj.ptr()); |
| 163 | PyArrayObject* labels_arr = |
| 164 | reinterpret_cast<PyArrayObject*>(labels_obj.ptr()); |
| 165 | CheckContiguousArray(data_arr, "data array", md_layer->channels(), |
| 166 | md_layer->height(), md_layer->width()); |
| 167 | CheckContiguousArray(labels_arr, "labels array", 1, 1, 1); |
| 168 | if (PyArray_DIMS(data_arr)[0] != PyArray_DIMS(labels_arr)[0]) { |
| 169 | throw std::runtime_error("data and labels must have the same first" |
| 170 | " dimension"); |
| 171 | } |
| 172 | if (PyArray_DIMS(data_arr)[0] % md_layer->batch_size() != 0) { |
| 173 | throw std::runtime_error("first dimensions of input arrays must be a" |
| 174 | " multiple of batch size"); |
| 175 | } |
| 176 | |
| 177 | md_layer->Reset(static_cast<Dtype*>(PyArray_DATA(data_arr)), |
| 178 | static_cast<Dtype*>(PyArray_DATA(labels_arr)), |
| 179 | PyArray_DIMS(data_arr)[0]); |
| 180 | } |
| 181 | |
| 182 | Solver<Dtype>* GetSolverFromFile(const string& filename) { |
| 183 | SolverParameter param; |
nothing calls this directly
no test coverage detected