def cntk_emit(original_framework, architecture_name, architecture_path, weight_path, test_input_path): from mmdnn.conversion.cntk.cntk_emitter import CntkEmitter # IR to code converted_file = TestModels.tmpdir + original_framework + '_cntk_' + architecture_name + "_converted" converted_file = converted_file.replace('.', '_') emitter = CntkEmitter((architecture_path, weight_path)) emitter.run(converted_file + '.py', None, 'test') del emitter del CntkEmitter model_converted = imp.load_source('CntkModel', converted_file + '.py').KitModel(weight_path) if 'rnn' not in architecture_name: func = TestKit.preprocess_func[original_framework][ architecture_name] img = func(test_input_path(architecture_name)) input_data = img else: sentence = np.load(test_input_path(architecture_name)) from keras.utils import to_categorical input_data = to_categorical(sentence, 30000)[0] predict = model_converted.eval( {model_converted.arguments[0]: [input_data]}) converted_predict = np.squeeze(predict) del model_converted del sys.modules['CntkModel'] os.remove(converted_file + '.py') return converted_predict
def CntkEmit(original_framework, architecture_name, architecture_path, weight_path, image_path): print("Testing {} from {} to CNTK.".format(architecture_name, original_framework)) # IR to code emitter = CntkEmitter((architecture_path, weight_path)) emitter.run("converted_model.py", None, 'test') del emitter # import converted model import converted_model reload_module(converted_model) model_converted = converted_model.KitModel(TestModels.tmpdir + architecture_name + "_converted.npy") func = TestKit.preprocess_func[original_framework][architecture_name] img = func(image_path) predict = model_converted.eval({model_converted.arguments[0]: [img]}) converted_predict = np.squeeze(predict) del model_converted del converted_model os.remove("converted_model.py") return converted_predict
def CntkEmit(original_framework, architecture_name, architecture_path, weight_path, image_path): # IR to code converted_file = original_framework + '_cntk_' + architecture_name + "_converted" converted_file = converted_file.replace('.', '_') emitter = CntkEmitter((architecture_path, weight_path)) emitter.run(converted_file + '.py', None, 'test') del emitter model_converted = __import__(converted_file).KitModel(weight_path) func = TestKit.preprocess_func[original_framework][architecture_name] img = func(image_path) predict = model_converted.eval({model_converted.arguments[0]:[img]}) converted_predict = np.squeeze(predict) del model_converted del sys.modules[converted_file] os.remove(converted_file + '.py') return converted_predict
def CntkEmit(original_framework, architecture_name, architecture_path, weight_path, image_path): # IR to code converted_file = original_framework + '_cntk_' + architecture_name + "_converted" converted_file = converted_file.replace('.', '_') emitter = CntkEmitter((architecture_path, weight_path)) emitter.run(converted_file + '.py', None, 'test') del emitter model_converted = __import__(converted_file).KitModel(weight_path) func = TestKit.preprocess_func[original_framework][architecture_name] img = func(image_path) predict = model_converted.eval({model_converted.arguments[0]:[img]}) converted_predict = np.squeeze(predict) del model_converted del sys.modules[converted_file] os.remove(converted_file + '.py') return converted_predict