在Android中运行经过TF训练的模型时应用崩溃

时间:2018-11-06 18:43:32

标签: android tensorflow

我正在尝试在我的Android应用中使用此链接模型。 https://github.com/machrisaa/tensorzoom

我还在我的应用程序中使用了其他经过tf训练的模型,效果很好,但是当我尝试在此模型应用程序上运行TensorFlowInferenceInterface时,每次都会崩溃。请帮助我找出出路;我在这里一无所知。

代码:

export const environment = {
  baseUrlWithSlash: 'http://site-prod.com/',
  logoffWarningTimeoutSeconds: 600,
  production: true,
  searchDelimiters: /[,;\n]+/
};

environment-local.ts
  export const environment = {
      baseUrlWithSlash: 'http://site-dev.com/',
      logoffWarningTimeoutSeconds: 600,
      production: true,
      searchDelimiters: /[,;\n]+/
    };

和相关的logcat输出是这样的:

  AssetManager assetManager = context.getResources().getAssets();
    sTFInterfaceSuper = new TensorFlowInferenceInterface(assetManager, MODEL_FILE_SUPER);

 public synchronized static Bitmap getSuperBitmap(final Bitmap bitmap) {
    if (sTFInterfaceSuper == null) {
        Log.d("dude","tf model is NOT initialized.");
        return null;
    }

    if (bitmap == null) {
        return null;
    }

    final int w = bitmap.getWidth();
    final int h = bitmap.getHeight();

    final int newW = 4 * w;
    final int newH = 4 * h;

    int[] mIntValues = new int[w * h];
    float[] mFlatIntValues = new float[w * h * 3];
    float[] mOutputs = new float[newW * newH * 3];

    int[] input_shape = new int[]{w, h, 3};

    bitmap.getPixels(mIntValues, 0, w, 0, 0, w, h);

    for (int i = 0; i < mIntValues.length; ++i) {
        final int val = mIntValues[i];
        mFlatIntValues[i * 3 + 0] = (float) ((val >> 16) & 0xFF) / 255;
        mFlatIntValues[i * 3 + 1] = (float) ((val >> 8) & 0xFF) / 255;
        mFlatIntValues[i * 3 + 2] = (float) (val & 0xFF) / 255;
    }

    final long start = System.currentTimeMillis();

    sTFInterfaceSuper.feed("input_shape",input_shape, 3);
    sTFInterfaceSuper.feed(INPUT_NAME_SUPER, mFlatIntValues, w, h, 3 );

    sTFInterfaceSuper.run(new String[] { OUTPUT_NAME_SUPER }, true);

    sTFInterfaceSuper.fetch(OUTPUT_NAME_SUPER, mOutputs);

    final long end = System.currentTimeMillis();
    Log.d("dude","%d millis Super time. " + (end - start));

    Bitmap output = Bitmap.createBitmap(newW, newH, Bitmap.Config.ARGB_8888);

    for (int y = 0; y < newH; y++) {
        for (int x = 0; x < newW; x++) {
            output.setPixel(x, y, (int)mOutputs[y * newW + x]);
        }
    }

    return output;
}

0 个答案:

没有答案