Beispiel #1
0
    def KerasEmit(original_framework, architecture_name, architecture_path,
                  weight_path, image_path):
        print("Testing {} from {} to Keras.".format(architecture_name,
                                                    original_framework))

        # IR to code
        emitter = Keras2Emitter((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)
        input_data = np.expand_dims(img, 0)

        predict = model_converted.predict(input_data)
        converted_predict = np.squeeze(predict)

        del model_converted
        del converted_model

        import keras.backend as K
        K.clear_session()

        os.remove("converted_model.py")
        return converted_predict
Beispiel #2
0
    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
Beispiel #3
0
    def TensorflowEmit(original_framework, architecture_name,
                       architecture_path, weight_path, image_path):
        print("Testing {} from {} to Tensorflow.".format(
            architecture_name, original_framework))

        # IR to code
        emitter = TensorflowEmitter((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")
        input_tf, model_tf = model_converted

        func = TestKit.preprocess_func[original_framework][architecture_name]
        img = func(image_path)
        input_data = np.expand_dims(img, 0)
        with tf.Session() as sess:
            init = tf.global_variables_initializer()
            sess.run(init)
            predict = sess.run(model_tf, feed_dict={input_tf: input_data})
        del model_converted
        del converted_model
        os.remove("converted_model.py")
        converted_predict = np.squeeze(predict)
        return converted_predict
    def CaffeEmit(original_framework, architecture_name, architecture_path, weight_path, image_path):
        print("Testing {} from {} to Caffe.".format(architecture_name, original_framework))

        # IR to code
        emitter = CaffeEmitter((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")
        # input_tf, model_tf = model_converted

        func = TestKit.preprocess_func[original_framework][architecture_name]
        img = func(image_path)