def transform_prediction_net(model_path_prefix, quantization):
    tensorflow_model_path = model_path_prefix + "/pred_net.pb"
    caffe_model_path_prefix = "asr_convolution_transformer_prediction_net"
    caffe_model_name = "asr_convolution_transformer_prediction_net"
    asr_caffe = Tensorflow2CaffeConvolutionTransformer(
        tensorflow_model_path,
        caffe_model_path_prefix,
        caffe_model_name,
        check=False,
        calc=True,
        quantization=quantization)
    data = {}
    data["label"] = np.array([[1]])
    asr_caffe.generate_prediction_net(data)
def transform_joint_net(model_path_prefix, data_path_prefix, quantization):
    tensorflow_model_path = model_path_prefix + "/joint_net.pb"
    caffe_model_path_prefix = "asr_convolution_transformer_joint_net"
    caffe_model_name = "asr_convolution_transformer_joint_net"
    asr_caffe = Tensorflow2CaffeConvolutionTransformer(
        tensorflow_model_path,
        caffe_model_path_prefix,
        caffe_model_name,
        check=False,
        calc=True,
        quantization=quantization)
    shapes = {}
    shapes["encoder"] = [1, 512]
    shapes["prediction_net"] = [1, 512]
    data = {}
    data["encoder"] = np.load(data_path_prefix + "/encoder.npy")
    data["prediction_net"] = np.load(data_path_prefix + "/pred_net.npy")
    asr_caffe.print_weight_map()
    asr_caffe.generate_joint_net(shapes, data)
def transform_encoder(model_path_prefix, data_path_prefix, quantization,
                      block_id_start, block_id_end):
    tensorflow_model_path = model_path_prefix + "/encoder.pb"
    caffe_model_path_prefix = "asr_convolution_transformer_encoder"
    caffe_model_name = "asr_convolution_transformer_encoder"
    first_frame = True
    asr_caffe = Tensorflow2CaffeConvolutionTransformer(
        tensorflow_model_path,
        caffe_model_path_prefix,
        caffe_model_name,
        nchwc8=True,
        first_frame=first_frame,
        check=False,
        calc=True,
        quantization=quantization)
    data = {}
    if (first_frame):
        data["sounds"] = np.load(data_path_prefix + "/sound0_frame0.npy")
    else:
        data["sounds"] = np.load(data_path_prefix + "/sound0_frame1.npy")
    asr_caffe.generate_encoder(data, block_id_start, block_id_end)
Beispiel #4
0
def transform_reference(model_path_prefix, data_path_prefix, quantization,
                        FFN_decomposition):
    tensorflow_model_path = model_path_prefix + "/encoder.pb"
    caffe_model_path_prefix = "asr_convolution_transformer_reference"
    caffe_model_name = "asr_convolution_transformer_reference"
    first_frame = True
    asr_caffe = Tensorflow2CaffeConvolutionTransformer(
        base_params,
        tensorflow_model_path,
        caffe_model_path_prefix,
        caffe_model_name,
        nchwc8=True,
        first_frame=first_frame,
        check=False,
        calc=True,
        quantization=quantization,
        FFN_decomposition=FFN_decomposition)
    data = {}
    data["reference"] = np.array([[
        42, 39, 42, 39, 41, 38, 14, 28, 6, 36, 25, 23, 32, 15, 8, 36, 33, 39,
        37, 19, 33, 8, 27, 27, 23, 5
    ]])
    out = asr_caffe.generate_reference(data)
    np.save("reference.npy", asr_caffe.get_tensor(out))
Beispiel #5
0
def transform_encoder(model_path_prefix, data_path_prefix, quantization,
                      FFN_decomposition):
    tensorflow_model_path = model_path_prefix + "/encoder.pb"
    caffe_model_path_prefix = "asr_convolution_transformer_encoder"
    caffe_model_name = "asr_convolution_transformer_encoder"
    first_frame = True
    asr_caffe = Tensorflow2CaffeConvolutionTransformer(
        base_params,
        tensorflow_model_path,
        caffe_model_path_prefix,
        caffe_model_name,
        nchwc8=True,
        first_frame=first_frame,
        check=False,
        calc=True,
        quantization=quantization,
        FFN_decomposition=FFN_decomposition)
    data = {}
    data["reference"] = np.load("reference.npy")
    if (first_frame):
        data["sounds"] = np.load(data_path_prefix + "/frame0.npy")
    else:
        data["sounds"] = np.load(data_path_prefix + "/frame1.npy")
    asr_caffe.generate_encoder(data)