Remove unnecessary quick test for deploy net

parent 2179b2b1
Pipeline #91673 passed with stages
in 4 minutes and 12 seconds
......@@ -14,8 +14,8 @@ class ${tc.fileNameWithoutEnding}:
_data_dir_ = os.path.join(_current_dir_, 'data', '${tc.fullArchitectureName}')
_model_dir_ = os.path.join(_current_dir_, 'model', '${tc.fullArchitectureName}')
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-->
_init_net_ = os.path.join(_model_dir_, 'init_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
......@@ -162,7 +162,7 @@ ${tc.include(tc.architecture.body)}
self.create_model(deploy_model, "data", device_opts)
print("Saving deploy model")
self.save_net(self.INIT_NET, self.PREDICT_NET, deploy_model)
self.save_net(self._init_net_, self._predict_net_, deploy_model)
def save_net(self, init_net_path, predict_net_path, model):
......
......@@ -3,7 +3,6 @@ from caffe2.python.predictor import mobile_exporter
from caffe2.proto import caffe2_pb2
import numpy as np
import cv2
import logging
<#list configurations as config>
import CNNCreator_${config.instanceName}
......@@ -33,7 +32,7 @@ if __name__ == "__main__":
<#if (config.configuration.optimizer)??>
opt_type='${config.optimizerName}',
<#list config.optimizerParams?keys as param>
<#--Adapt parameter names since parameter names in Caffe2 are different than in CNNTrainLang-->
<#--To adapt parameter names since parameter names in Caffe2 are different than in CNNTrainLang-->
<#assign paramName = param>
<#if param == "learning_rate">
<#assign paramName = "base_learning_rate">
......@@ -50,36 +49,3 @@ if __name__ == "__main__":
)
</#list>
<#--Below code can be removed. It is only an specific example to verify that deploy_net works-->
print '\n********************************************'
print("Loading Deploy model")
<#list configurations as config>
<#if (config.context)??>
context='${config.context}'
<#else>
context = 'gpu'
</#if>
<#--Code section that decides the mode cannot be moved into the load_net function since workspace.FeedBlob also needs this parameter-->
if context == 'cpu':
device_opts = core.DeviceOption(caffe2_pb2.CPU, 0)
print("CPU mode selected")
elif context == 'gpu':
device_opts = core.DeviceOption(caffe2_pb2.CUDA, 0)
print("GPU mode selected")
${config.instanceName}.load_net(${config.instanceName}.INIT_NET, ${config.instanceName}.PREDICT_NET, device_opts=device_opts)
</#list>
img = cv2.imread("./test_img/3.jpg") # Load test image
img = cv2.resize(img, (28,28)) # Resize to 28x28
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY ) # Covert to grayscale
img = img.reshape((1,1,28,28)).astype('float32') # Reshape to (1,1,28,28)
workspace.FeedBlob("data", img, device_option=device_opts) # FeedBlob
workspace.RunNet('deploy_net', num_iter=1) # Forward
print("\nInput: {}".format(img.shape))
pred = workspace.FetchBlob("predictions")
print("Output: {}".format(pred))
print("Output class: {}".format(np.argmax(pred)))
......@@ -14,8 +14,8 @@ class CNNCreator_Alexnet:
_data_dir_ = os.path.join(_current_dir_, 'data', 'Alexnet')
_model_dir_ = os.path.join(_current_dir_, 'model', 'Alexnet')
INIT_NET = os.path.join(_model_dir_, 'init_net.pb')
PREDICT_NET = os.path.join(_model_dir_, 'predict_net.pb')
_init_net_ = os.path.join(_model_dir_, 'init_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
......@@ -254,7 +254,7 @@ class CNNCreator_Alexnet:
self.create_model(deploy_model, "data", device_opts)
print("Saving deploy model")
self.save_net(self.INIT_NET, self.PREDICT_NET, deploy_model)
self.save_net(self._init_net_, self._predict_net_, deploy_model)
def save_net(self, init_net_path, predict_net_path, model):
......
......@@ -14,8 +14,8 @@ class CNNCreator_CifarClassifierNetwork:
_data_dir_ = os.path.join(_current_dir_, 'data', 'CifarClassifierNetwork')
_model_dir_ = os.path.join(_current_dir_, 'model', 'CifarClassifierNetwork')
INIT_NET = os.path.join(_model_dir_, 'init_net.pb')
PREDICT_NET = os.path.join(_model_dir_, 'predict_net.pb')
_init_net_ = os.path.join(_model_dir_, 'init_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
......@@ -339,7 +339,7 @@ class CNNCreator_CifarClassifierNetwork:
self.create_model(deploy_model, "data", device_opts)
print("Saving deploy model")
self.save_net(self.INIT_NET, self.PREDICT_NET, deploy_model)
self.save_net(self._init_net_, self._predict_net_, deploy_model)
def save_net(self, init_net_path, predict_net_path, model):
......
......@@ -14,8 +14,8 @@ class CNNCreator_VGG16:
_data_dir_ = os.path.join(_current_dir_, 'data', 'VGG16')
_model_dir_ = os.path.join(_current_dir_, 'model', 'VGG16')
INIT_NET = os.path.join(_model_dir_, 'init_net.pb')
PREDICT_NET = os.path.join(_model_dir_, 'predict_net.pb')
_init_net_ = os.path.join(_model_dir_, 'init_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
......@@ -229,7 +229,7 @@ class CNNCreator_VGG16:
self.create_model(deploy_model, "data", device_opts)
print("Saving deploy model")
self.save_net(self.INIT_NET, self.PREDICT_NET, deploy_model)
self.save_net(self._init_net_, self._predict_net_, deploy_model)
def save_net(self, init_net_path, predict_net_path, model):
......
......@@ -3,7 +3,6 @@ from caffe2.python.predictor import mobile_exporter
from caffe2.proto import caffe2_pb2
import numpy as np
import cv2
import logging
import CNNCreator_emptyConfig
......@@ -17,28 +16,3 @@ if __name__ == "__main__":
emptyConfig.train(
)
print '\n********************************************'
print("Loading Deploy model")
context = 'gpu'
if context == 'cpu':
device_opts = core.DeviceOption(caffe2_pb2.CPU, 0)
print("CPU mode selected")
elif context == 'gpu':
device_opts = core.DeviceOption(caffe2_pb2.CUDA, 0)
print("GPU mode selected")
emptyConfig.load_net(emptyConfig.INIT_NET, emptyConfig.PREDICT_NET, device_opts=device_opts)
img = cv2.imread("./test_img/3.jpg") # Load test image
img = cv2.resize(img, (28,28)) # Resize to 28x28
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY ) # Covert to grayscale
img = img.reshape((1,1,28,28)).astype('float32') # Reshape to (1,1,28,28)
workspace.FeedBlob("data", img, device_option=device_opts) # FeedBlob
workspace.RunNet('deploy_net', num_iter=1) # Forward
print("\nInput: {}".format(img.shape))
pred = workspace.FetchBlob("predictions")
print("Output: {}".format(pred))
print("Output class: {}".format(np.argmax(pred)))
......@@ -3,7 +3,6 @@ from caffe2.python.predictor import mobile_exporter
from caffe2.proto import caffe2_pb2
import numpy as np
import cv2
import logging
import CNNCreator_fullConfig
......@@ -27,28 +26,3 @@ if __name__ == "__main__":
base_learning_rate=0.001,
stepsize=1000
)
print '\n********************************************'
print("Loading Deploy model")
context='gpu'
if context == 'cpu':
device_opts = core.DeviceOption(caffe2_pb2.CPU, 0)
print("CPU mode selected")
elif context == 'gpu':
device_opts = core.DeviceOption(caffe2_pb2.CUDA, 0)
print("GPU mode selected")
fullConfig.load_net(fullConfig.INIT_NET, fullConfig.PREDICT_NET, device_opts=device_opts)
img = cv2.imread("./test_img/3.jpg") # Load test image
img = cv2.resize(img, (28,28)) # Resize to 28x28
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY ) # Covert to grayscale
img = img.reshape((1,1,28,28)).astype('float32') # Reshape to (1,1,28,28)
workspace.FeedBlob("data", img, device_option=device_opts) # FeedBlob
workspace.RunNet('deploy_net', num_iter=1) # Forward
print("\nInput: {}".format(img.shape))
pred = workspace.FetchBlob("predictions")
print("Output: {}".format(pred))
print("Output class: {}".format(np.argmax(pred)))
......@@ -3,7 +3,6 @@ from caffe2.python.predictor import mobile_exporter
from caffe2.proto import caffe2_pb2
import numpy as np
import cv2
import logging
import CNNCreator_simpleConfig
......@@ -20,28 +19,3 @@ if __name__ == "__main__":
opt_type='adam',
base_learning_rate=0.001
)
print '\n********************************************'
print("Loading Deploy model")
context = 'gpu'
if context == 'cpu':
device_opts = core.DeviceOption(caffe2_pb2.CPU, 0)
print("CPU mode selected")
elif context == 'gpu':
device_opts = core.DeviceOption(caffe2_pb2.CUDA, 0)
print("GPU mode selected")
simpleConfig.load_net(simpleConfig.INIT_NET, simpleConfig.PREDICT_NET, device_opts=device_opts)
img = cv2.imread("./test_img/3.jpg") # Load test image
img = cv2.resize(img, (28,28)) # Resize to 28x28
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY ) # Covert to grayscale
img = img.reshape((1,1,28,28)).astype('float32') # Reshape to (1,1,28,28)
workspace.FeedBlob("data", img, device_option=device_opts) # FeedBlob
workspace.RunNet('deploy_net', num_iter=1) # Forward
print("\nInput: {}".format(img.shape))
pred = workspace.FetchBlob("predictions")
print("Output: {}".format(pred))
print("Output class: {}".format(np.argmax(pred)))
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