Commit 5ffb5d70 authored by Evgeny Kusmenko's avatar Evgeny Kusmenko
Browse files

Merge branch 'bugfix_relation_epoch_iterations' into 'master'

Bugfix: corrected relation between epochs and iterations used in Caffe2

See merge request !14
parents 1d10ccac 4dd7f0e9
Pipeline #90369 passed with stages
in 6 minutes and 29 seconds
...@@ -2,6 +2,7 @@ from caffe2.python import workspace, core, model_helper, brew, optimizer ...@@ -2,6 +2,7 @@ from caffe2.python import workspace, core, model_helper, brew, optimizer
from caffe2.python.predictor import mobile_exporter from caffe2.python.predictor import mobile_exporter
from caffe2.proto import caffe2_pb2 from caffe2.proto import caffe2_pb2
import numpy as np import numpy as np
import math
import logging import logging
import os import os
import sys import sys
...@@ -16,6 +17,17 @@ class ${tc.fileNameWithoutEnding}: ...@@ -16,6 +17,17 @@ class ${tc.fileNameWithoutEnding}:
INIT_NET = os.path.join(_model_dir_, 'init_net.pb')<#--TODO: Change name to _init_net_ once it is not used in CNNTrainer for quick testing purposes--> INIT_NET = os.path.join(_model_dir_, 'init_net.pb')<#--TODO: Change name to _init_net_ once it is not used in CNNTrainer for quick testing purposes-->
PREDICT_NET = os.path.join(_model_dir_, 'predict_net.pb')<#--TODO:Change name to _predict_net_ once it is not used in CNNTrainer for quick testing purposes--> PREDICT_NET = os.path.join(_model_dir_, 'predict_net.pb')<#--TODO:Change name to _predict_net_ once it is not used in CNNTrainer for quick testing purposes-->
def get_total_num_iter(self, num_epoch, batch_size, dataset_size):
#Force floating point calculation
batch_size_float = float(batch_size)
dataset_size_float = float(dataset_size)
iterations_float = math.ceil(num_epoch*(dataset_size_float/batch_size_float))
iterations_int = int(iterations_float)
return iterations_int
def add_input(self, model, batch_size, db, db_type, device_opts): def add_input(self, model, batch_size, db, db_type, device_opts):
with core.DeviceScope(device_opts): with core.DeviceScope(device_opts):
# load the data # load the data
...@@ -110,8 +122,9 @@ ${tc.include(tc.architecture.body)} ...@@ -110,8 +122,9 @@ ${tc.include(tc.architecture.body)}
workspace.CreateNet(train_model.net, overwrite=True) workspace.CreateNet(train_model.net, overwrite=True)
# Main Training Loop # Main Training Loop
print("== Starting Training for " + str(num_epoch) + " epochs ==") iterations = self.get_total_num_iter(num_epoch, batch_size, train_dataset_size)
for i in range(num_epoch): print("** Starting Training for " + str(num_epoch) + " epochs = " + str(iterations) + " iterations **")
for i in range(iterations):
workspace.RunNet(train_model.net) workspace.RunNet(train_model.net)
if i % 50 == 0: if i % 50 == 0:
print 'Iter ' + str(i) + ': ' + 'Loss ' + str(workspace.FetchBlob("loss")) + ' - ' + 'Accuracy ' + str(workspace.FetchBlob('accuracy')) print 'Iter ' + str(i) + ': ' + 'Loss ' + str(workspace.FetchBlob("loss")) + ' - ' + 'Accuracy ' + str(workspace.FetchBlob('accuracy'))
......
...@@ -2,6 +2,7 @@ from caffe2.python import workspace, core, model_helper, brew, optimizer ...@@ -2,6 +2,7 @@ from caffe2.python import workspace, core, model_helper, brew, optimizer
from caffe2.python.predictor import mobile_exporter from caffe2.python.predictor import mobile_exporter
from caffe2.proto import caffe2_pb2 from caffe2.proto import caffe2_pb2
import numpy as np import numpy as np
import math
import logging import logging
import os import os
import sys import sys
...@@ -16,6 +17,17 @@ class CNNCreator_Alexnet: ...@@ -16,6 +17,17 @@ class CNNCreator_Alexnet:
INIT_NET = os.path.join(_model_dir_, 'init_net.pb') INIT_NET = os.path.join(_model_dir_, 'init_net.pb')
PREDICT_NET = os.path.join(_model_dir_, 'predict_net.pb') PREDICT_NET = os.path.join(_model_dir_, 'predict_net.pb')
def get_total_num_iter(self, num_epoch, batch_size, dataset_size):
#Force floating point calculation
batch_size_float = float(batch_size)
dataset_size_float = float(dataset_size)
iterations_float = math.ceil(num_epoch*(dataset_size_float/batch_size_float))
iterations_int = int(iterations_float)
return iterations_int
def add_input(self, model, batch_size, db, db_type, device_opts): def add_input(self, model, batch_size, db, db_type, device_opts):
with core.DeviceScope(device_opts): with core.DeviceScope(device_opts):
# load the data # load the data
...@@ -202,8 +214,9 @@ class CNNCreator_Alexnet: ...@@ -202,8 +214,9 @@ class CNNCreator_Alexnet:
workspace.CreateNet(train_model.net, overwrite=True) workspace.CreateNet(train_model.net, overwrite=True)
# Main Training Loop # Main Training Loop
print("== Starting Training for " + str(num_epoch) + " epochs ==") iterations = self.get_total_num_iter(num_epoch, batch_size, train_dataset_size)
for i in range(num_epoch): print("** Starting Training for " + str(num_epoch) + " epochs = " + str(iterations) + " iterations **")
for i in range(iterations):
workspace.RunNet(train_model.net) workspace.RunNet(train_model.net)
if i % 50 == 0: if i % 50 == 0:
print 'Iter ' + str(i) + ': ' + 'Loss ' + str(workspace.FetchBlob("loss")) + ' - ' + 'Accuracy ' + str(workspace.FetchBlob('accuracy')) print 'Iter ' + str(i) + ': ' + 'Loss ' + str(workspace.FetchBlob("loss")) + ' - ' + 'Accuracy ' + str(workspace.FetchBlob('accuracy'))
......
...@@ -2,6 +2,7 @@ from caffe2.python import workspace, core, model_helper, brew, optimizer ...@@ -2,6 +2,7 @@ from caffe2.python import workspace, core, model_helper, brew, optimizer
from caffe2.python.predictor import mobile_exporter from caffe2.python.predictor import mobile_exporter
from caffe2.proto import caffe2_pb2 from caffe2.proto import caffe2_pb2
import numpy as np import numpy as np
import math
import logging import logging
import os import os
import sys import sys
...@@ -16,6 +17,17 @@ class CNNCreator_CifarClassifierNetwork: ...@@ -16,6 +17,17 @@ class CNNCreator_CifarClassifierNetwork:
INIT_NET = os.path.join(_model_dir_, 'init_net.pb') INIT_NET = os.path.join(_model_dir_, 'init_net.pb')
PREDICT_NET = os.path.join(_model_dir_, 'predict_net.pb') PREDICT_NET = os.path.join(_model_dir_, 'predict_net.pb')
def get_total_num_iter(self, num_epoch, batch_size, dataset_size):
#Force floating point calculation
batch_size_float = float(batch_size)
dataset_size_float = float(dataset_size)
iterations_float = math.ceil(num_epoch*(dataset_size_float/batch_size_float))
iterations_int = int(iterations_float)
return iterations_int
def add_input(self, model, batch_size, db, db_type, device_opts): def add_input(self, model, batch_size, db, db_type, device_opts):
with core.DeviceScope(device_opts): with core.DeviceScope(device_opts):
# load the data # load the data
...@@ -287,8 +299,9 @@ class CNNCreator_CifarClassifierNetwork: ...@@ -287,8 +299,9 @@ class CNNCreator_CifarClassifierNetwork:
workspace.CreateNet(train_model.net, overwrite=True) workspace.CreateNet(train_model.net, overwrite=True)
# Main Training Loop # Main Training Loop
print("== Starting Training for " + str(num_epoch) + " epochs ==") iterations = self.get_total_num_iter(num_epoch, batch_size, train_dataset_size)
for i in range(num_epoch): print("** Starting Training for " + str(num_epoch) + " epochs = " + str(iterations) + " iterations **")
for i in range(iterations):
workspace.RunNet(train_model.net) workspace.RunNet(train_model.net)
if i % 50 == 0: if i % 50 == 0:
print 'Iter ' + str(i) + ': ' + 'Loss ' + str(workspace.FetchBlob("loss")) + ' - ' + 'Accuracy ' + str(workspace.FetchBlob('accuracy')) print 'Iter ' + str(i) + ': ' + 'Loss ' + str(workspace.FetchBlob("loss")) + ' - ' + 'Accuracy ' + str(workspace.FetchBlob('accuracy'))
......
...@@ -2,6 +2,7 @@ from caffe2.python import workspace, core, model_helper, brew, optimizer ...@@ -2,6 +2,7 @@ from caffe2.python import workspace, core, model_helper, brew, optimizer
from caffe2.python.predictor import mobile_exporter from caffe2.python.predictor import mobile_exporter
from caffe2.proto import caffe2_pb2 from caffe2.proto import caffe2_pb2
import numpy as np import numpy as np
import math
import logging import logging
import os import os
import sys import sys
...@@ -16,6 +17,17 @@ class CNNCreator_VGG16: ...@@ -16,6 +17,17 @@ class CNNCreator_VGG16:
INIT_NET = os.path.join(_model_dir_, 'init_net.pb') INIT_NET = os.path.join(_model_dir_, 'init_net.pb')
PREDICT_NET = os.path.join(_model_dir_, 'predict_net.pb') PREDICT_NET = os.path.join(_model_dir_, 'predict_net.pb')
def get_total_num_iter(self, num_epoch, batch_size, dataset_size):
#Force floating point calculation
batch_size_float = float(batch_size)
dataset_size_float = float(dataset_size)
iterations_float = math.ceil(num_epoch*(dataset_size_float/batch_size_float))
iterations_int = int(iterations_float)
return iterations_int
def add_input(self, model, batch_size, db, db_type, device_opts): def add_input(self, model, batch_size, db, db_type, device_opts):
with core.DeviceScope(device_opts): with core.DeviceScope(device_opts):
# load the data # load the data
...@@ -177,8 +189,9 @@ class CNNCreator_VGG16: ...@@ -177,8 +189,9 @@ class CNNCreator_VGG16:
workspace.CreateNet(train_model.net, overwrite=True) workspace.CreateNet(train_model.net, overwrite=True)
# Main Training Loop # Main Training Loop
print("== Starting Training for " + str(num_epoch) + " epochs ==") iterations = self.get_total_num_iter(num_epoch, batch_size, train_dataset_size)
for i in range(num_epoch): print("** Starting Training for " + str(num_epoch) + " epochs = " + str(iterations) + " iterations **")
for i in range(iterations):
workspace.RunNet(train_model.net) workspace.RunNet(train_model.net)
if i % 50 == 0: if i % 50 == 0:
print 'Iter ' + str(i) + ': ' + 'Loss ' + str(workspace.FetchBlob("loss")) + ' - ' + 'Accuracy ' + str(workspace.FetchBlob('accuracy')) print 'Iter ' + str(i) + ': ' + 'Loss ' + str(workspace.FetchBlob("loss")) + ' - ' + 'Accuracy ' + str(workspace.FetchBlob('accuracy'))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment