| 165 | } |
| 166 | |
| 167 | void Net_SetInputArrays(Net<Dtype>* net, bp::object data_obj, |
| 168 | bp::object labels_obj) { |
| 169 | // check that this network has an input MemoryDataLayer |
| 170 | shared_ptr<MemoryDataLayer<Dtype> > md_layer = |
| 171 | boost::dynamic_pointer_cast<MemoryDataLayer<Dtype> >(net->layers()[0]); |
| 172 | if (!md_layer) { |
| 173 | throw std::runtime_error("set_input_arrays may only be called if the" |
| 174 | " first layer is a MemoryDataLayer"); |
| 175 | } |
| 176 | |
| 177 | // check that we were passed appropriately-sized contiguous memory |
| 178 | PyArrayObject* data_arr = |
| 179 | reinterpret_cast<PyArrayObject*>(data_obj.ptr()); |
| 180 | PyArrayObject* labels_arr = |
| 181 | reinterpret_cast<PyArrayObject*>(labels_obj.ptr()); |
| 182 | CheckContiguousArray(data_arr, "data array", md_layer->channels(), |
| 183 | md_layer->height(), md_layer->width()); |
| 184 | CheckContiguousArray(labels_arr, "labels array", 1, 1, 1); |
| 185 | if (PyArray_DIMS(data_arr)[0] != PyArray_DIMS(labels_arr)[0]) { |
| 186 | throw std::runtime_error("data and labels must have the same first" |
| 187 | " dimension"); |
| 188 | } |
| 189 | if (PyArray_DIMS(data_arr)[0] % md_layer->batch_size() != 0) { |
| 190 | throw std::runtime_error("first dimensions of input arrays must be a" |
| 191 | " multiple of batch size"); |
| 192 | } |
| 193 | |
| 194 | md_layer->Reset(static_cast<Dtype*>(PyArray_DATA(data_arr)), |
| 195 | static_cast<Dtype*>(PyArray_DATA(labels_arr)), |
| 196 | PyArray_DIMS(data_arr)[0]); |
| 197 | } |
| 198 | |
| 199 | Solver<Dtype>* GetSolverFromFile(const string& filename) { |
| 200 | SolverParameter param; |
nothing calls this directly
no test coverage detected