* @param iteration_per_epoch iteration per epoch
* @return bool true if iteration has finished
*/
-bool setIteration(unsigned int &iteration, unsigned int iteration_per_epoch) {
+bool updateIteration(unsigned int &iteration,
+ unsigned int iteration_per_epoch) {
if (iteration++ == iteration_per_epoch) {
iteration = 0;
return true;
}
};
- if (setIteration(iteration, iteration_for_one_epoch)) {
+ if (updateIteration(iteration, iteration_for_one_epoch)) {
*last = true;
return;
}
for (unsigned int i = 0; i < Cifar100DataLoader::ImageSize; ++i) {
uint8_t data;
file.read(reinterpret_cast<char *>(&data), sizeof(uint8_t));
- *input_ = data;
+ *input_ = data / 255.f;
input_++;
}
};
unsigned int idx_pos = current_iteration * batch;
- if (setIteration(current_iteration, iteration_per_epoch)) {
+ if (updateIteration(current_iteration, iteration_per_epoch)) {
*last = true;
std::shuffle(idxes.begin(), idxes.end(), rng);
return;
}
+
+ *last = false;
unsigned int idx_pos_end =
current_iteration * batch; // iteration increased by 1
{withKey("name", block_name), withKey("activation", "relu")});
if (downsample) {
- return {a1, a2, a3, b1, c1, c2};
+ return {b1, a1, a2, a3, c1, c2};
} else {
return {a1, a2, a3, c1, c2};
}
blocks.push_back(resnetBlock("conv2_1", "conv2_0", 128, 3, false));
blocks.push_back(resnetBlock("conv3_0", "conv2_1", 256, 3, true));
blocks.push_back(resnetBlock("conv3_1", "conv3_0", 256, 3, false));
- blocks.push_back(resnetBlock("conv4_0", "conv3_1", 256, 3, true));
- blocks.push_back(resnetBlock("conv4_1", "conv4_0", 256, 3, false));
+ blocks.push_back(resnetBlock("conv4_0", "conv3_1", 512, 3, true));
+ blocks.push_back(resnetBlock("conv4_1", "conv4_0", 512, 3, false));
for (auto &block : blocks) {
layers.insert(layers.end(), block.begin(), block.end());
void createAndRun(unsigned int epochs, unsigned int batch_size,
UserDataType *user_data) {
ModelHandle model = createResnet18();
- model->setProperty(
- {withKey("batch_size", batch_size), withKey("epochs", epochs)});
+ model->setProperty({withKey("batch_size", batch_size),
+ withKey("epochs", epochs),
+ withKey("save_path", "resnet_full.bin")});
- auto optimizer = ml::train::createOptimizer("adam");
+ auto optimizer = ml::train::createOptimizer("adam", {"learning_rate=0.001"});
model->setOptimizer(std::move(optimizer));
int status = model->compile();
}
try {
- createAndRun(epoch, 128, &user_data);
+ createAndRun(epoch, batch_size, &user_data);
} catch (std::exception &e) {
std::cerr << "uncaught error while running! details: " << e.what() << '\n';
return 1;
(*iter)->read(model_file);
}
- checkedRead(model_file, (char *)&tmp.epoch_idx, sizeof(epoch_idx),
- "[NeuralNetwork::readModel] failed to read epoch_idx");
- checkedRead(model_file, (char *)&tmp.iter, sizeof(iter),
- "[NeuralNetwork::readModel] failed to read iteration");
+ try {
+ /// this is assuming that the failure is allowed at the end of the file
+ /// read. so, after this line, additional read shouldn't be called
+ checkedRead(model_file, (char *)&tmp.epoch_idx, sizeof(epoch_idx),
+ "[NeuralNetwork::readModel] failed to read epoch_idx");
+ checkedRead(model_file, (char *)&tmp.iter, sizeof(iter),
+ "[NeuralNetwork::readModel] failed to read iteration");
+ } catch (...) {
+ model_file.close();
+ std::cerr << "failed to read epoch idx, proceeding with default index\n";
+ }
model_file.close();
ml_logi("read modelfile: %s", save_path.c_str());
int count = 0;
while (true) {
+
if (data_buffer->getDataFromBuffer(nntrainer::BufferType::BUF_TRAIN,
in.getData(), label.getData())) {
try {
/** print layer properties */
// TODO: get sorted layers if initialized
auto layers = model_graph.getLayerNodes();
- for (auto &layer : layers)
+ for (auto &layer : layers) {
layer->getObject()->printPreset(out, layerPrintPreset);
+ }
/// @todo Add status to check neuralnet has been run. #290
}