当前位置: 首页>>代码示例>>Java>>正文


Java TensorFlowInferenceInterface类代码示例

本文整理汇总了Java中org.tensorflow.contrib.android.TensorFlowInferenceInterface的典型用法代码示例。如果您正苦于以下问题:Java TensorFlowInferenceInterface类的具体用法?Java TensorFlowInferenceInterface怎么用?Java TensorFlowInferenceInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TensorFlowInferenceInterface类属于org.tensorflow.contrib.android包,在下文中一共展示了TensorFlowInferenceInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import org.tensorflow.contrib.android.TensorFlowInferenceInterface; //导入依赖的package包/类
/** Initializes a native TensorFlow session for classifying images. */
public static Classifier create(
    final AssetManager assetManager,
    final String modelFilename,
    final int inputSize,
    final String inputName,
    final String outputName,
    final int blockSize) {
  TensorFlowYoloDetector d = new TensorFlowYoloDetector();
  d.inputName = inputName;
  d.inputSize = inputSize;

  // Pre-allocate buffers.
  d.outputNames = outputName.split(",");
  d.intValues = new int[inputSize * inputSize];
  d.floatValues = new float[inputSize * inputSize * 3];
  d.blockSize = blockSize;

  d.inferenceInterface = new TensorFlowInferenceInterface(assetManager, modelFilename);

  return d;
}
 
开发者ID:Jamjomjara,项目名称:snu-artoon,代码行数:23,代码来源:TensorFlowYoloDetector.java

示例2: onCreate

import org.tensorflow.contrib.android.TensorFlowInferenceInterface; //导入依赖的package包/类
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        bufferSize = AudioRecord.getMinBufferSize(16000,
                AudioFormat.CHANNEL_IN_MONO,
                AudioFormat.ENCODING_PCM_16BIT);

        setButtonHandlers();
        enableButtons(false);

        inferenceInterface = new TensorFlowInferenceInterface();
        inferenceInterface.initializeTensorFlow(getAssets(), MODEL_FILE);
//        tensorFlowSample();

    }
 
开发者ID:ranatrk,项目名称:AudioGenderIdentifier,代码行数:18,代码来源:MainActivity.java

示例3: tensorFlowSample

import org.tensorflow.contrib.android.TensorFlowInferenceInterface; //导入依赖的package包/类
public void tensorFlowSample(){
    float num1 = 0.0f;
    float num2 = 3.33f;
    float num3 = 1.2f;

    String MODEL_FILE = "file:///android_asset/optimized_tfdroid2.pb";
    String INPUT_NODE = "I";
    String OUTPUT_NODE = "O";
    int[] INPUT_SIZE = {1,3};


    inferenceInterface = new TensorFlowInferenceInterface();
    inferenceInterface.initializeTensorFlow(getAssets(), MODEL_FILE);
    float[] inputFloats = {num1, num2, num3};

    inferenceInterface.fillNodeFloat(INPUT_NODE, INPUT_SIZE, inputFloats);
    inferenceInterface.runInference(new String[] {OUTPUT_NODE});


    float[] resu = new float[2];
    inferenceInterface.readNodeFloat(OUTPUT_NODE, resu);

    Log.v("output_mode" , Arrays.toString(resu));
}
 
开发者ID:ranatrk,项目名称:AudioGenderIdentifier,代码行数:25,代码来源:MainActivity.java

示例4: onPreviewSizeChosen

import org.tensorflow.contrib.android.TensorFlowInferenceInterface; //导入依赖的package包/类
@Override
public void onPreviewSizeChosen(final Size size, final int rotation) {
  final float textSizePx =
      TypedValue.applyDimension(
          TypedValue.COMPLEX_UNIT_DIP, TEXT_SIZE_DIP, getResources().getDisplayMetrics());
  borderedText = new BorderedText(textSizePx);
  borderedText.setTypeface(Typeface.MONOSPACE);

  inferenceInterface = new TensorFlowInferenceInterface(getAssets(), MODEL_FILE);

  previewWidth = size.getWidth();
  previewHeight = size.getHeight();

  final Display display = getWindowManager().getDefaultDisplay();
  final int screenOrientation = display.getRotation();

  LOGGER.i("Sensor orientation: %d, Screen orientation: %d", rotation, screenOrientation);

  sensorOrientation = rotation + screenOrientation;

  addCallback(
      new DrawCallback() {
        @Override
        public void drawCallback(final Canvas canvas) {
          renderDebug(canvas);
        }
      });

  adapter = new ImageGridAdapter();
  grid = (GridView) findViewById(R.id.grid_layout);
  grid.setAdapter(adapter);
  grid.setOnTouchListener(gridTouchAdapter);

  setStyle(adapter.items[0], 1.0f);
}
 
开发者ID:apacha,项目名称:TensorflowAndroidDemo,代码行数:36,代码来源:StylizeActivity.java

示例5: TensorFlowImageClassifier

import org.tensorflow.contrib.android.TensorFlowInferenceInterface; //导入依赖的package包/类
/**
 * Initializes a native TensorFlow session for classifying images.
 *
 * @param context The activity that instantiates this.
 */
public TensorFlowImageClassifier(Context context) {
    this.inferenceInterface = new TensorFlowInferenceInterface(
            context.getAssets(),
            Helper.MODEL_FILE);
    this.labels = Helper.readLabels(context);

    // Pre-allocate buffers.
    intValues = new int[Helper.IMAGE_SIZE * Helper.IMAGE_SIZE];
    floatValues = new float[Helper.IMAGE_SIZE * Helper.IMAGE_SIZE * 3];
    outputs = new float[Helper.NUM_CLASSES];
}
 
开发者ID:FoxLabMakerSpace,项目名称:SIGHT-For-the-Blind,代码行数:17,代码来源:TensorFlowImageClassifier.java

示例6: InitSession

import org.tensorflow.contrib.android.TensorFlowInferenceInterface; //导入依赖的package包/类
TensorFlowInferenceInterface InitSession(){
    inferenceInterface = new TensorFlowInferenceInterface();
    inferenceInterface.initializeTensorFlow(getActivity().getAssets(), MODEL_FILE);
    OutputNodes = LoadFile(OUTPUT_NODES);
    WORD_MAP = LoadFile("idmap");
    return inferenceInterface;
}
 
开发者ID:neural-nuts,项目名称:Cam2Caption,代码行数:8,代码来源:Camera2BasicFragment.java

示例7: init

import org.tensorflow.contrib.android.TensorFlowInferenceInterface; //导入依赖的package包/类
@Override
public void init() {
    //Check if the models downloaded?
    if (!isModelDownloaded())
        throw new RuntimeException("Models are not downloaded yet. Download them first.");

    this.inputName = INPUT_NAME;
    this.outputName = OUTPUT_NAME;

    // Read the label names into memory.
    this.labels = readLabels(TFUtils.getImageLabels(getContext()));
    Log.i(TAG, "Read " + labels.size() + ", " + NUM_CLASSES + " specified");

    this.inputSize = INPUT_SIZE;
    this.imageMean = IMAGE_MEAN;
    this.imageStd = IMAGE_STD;

    // Pre-allocate buffers.
    this.outputNames = new String[]{outputName};
    this.floatValues = new float[inputSize * inputSize * 3];
    this.outputs = new float[NUM_CLASSES];
    this.mBmpPixelValues = new int[inputSize * inputSize];

    //Initialize TF
    mTensorFlowInferenceInterface = new TensorFlowInferenceInterface(getContext().getAssets(),
            TFUtils.getImageGraph(getContext()).getAbsolutePath());
}
 
开发者ID:kevalpatel2106,项目名称:smart-lens,代码行数:28,代码来源:TFImageClassifier.java

示例8: create

import org.tensorflow.contrib.android.TensorFlowInferenceInterface; //导入依赖的package包/类
/**
 * This function will create the TensorFlow inference interface and will populate all
 * the necessary data needed for inference.
 */
public static HangulClassifier create(AssetManager assetManager,
                                      String modelPath, String labelFile, int inputDimension,
                                      String inputName, String keepProbName,
                                      String outputName) throws IOException {

    HangulClassifier classifier = new HangulClassifier();

    // These refer to the names of the nodes we care about in the model graph.
    classifier.inputName = inputName;
    classifier.keepProbName = keepProbName;
    classifier.outputName = outputName;

    // Read the labels from the given label file.
    classifier.labels = readLabels(assetManager, labelFile);

    // Create the TensorFlow interface using the specified model.
    classifier.tfInterface = new TensorFlowInferenceInterface(assetManager, modelPath);
    int numClasses = classifier.labels.size();

    // The size (in pixels) of each dimension of the image. Each dimension should be the same
    // since this is a square image.
    classifier.imageDimension = inputDimension;

    // This is a list of output nodes which should be filled by the inference pass.
    classifier.outputNames = new String[] { outputName };

    // This is the output node we care about.
    classifier.outputName = outputName;

    // The float buffer where the output of the softmax/output node will be stored.
    classifier.output = new float[numClasses];

    return classifier;
}
 
开发者ID:IBM,项目名称:tensorflow-hangul-recognition,代码行数:39,代码来源:HangulClassifier.java

示例9: create

import org.tensorflow.contrib.android.TensorFlowInferenceInterface; //导入依赖的package包/类
/** Initializes a native TensorFlow session for classifying images. */
public static Classifier create(
    final AssetManager assetManager,
    final String modelFilename,
    final int inputSize,
    final String inputName,
    final String outputName,
    final int blockSize) {
  TensorFlowYoloDetector d = new TensorFlowYoloDetector();
  d.inputName = inputName;
  d.inputSize = inputSize;

  // Pre-allocate buffers.
  d.outputNames = outputName.split(",");
  d.intValues = new int[inputSize * inputSize];
  d.floatValues = new float[inputSize * inputSize * 3];
  d.blockSize = blockSize;

  d.inferenceInterface = new TensorFlowInferenceInterface();

  final int status = d.inferenceInterface.initializeTensorFlow(assetManager, modelFilename);
  if (status != 0) {
    LOGGER.e("TF init status: " + status);
    throw new RuntimeException("TF init status (" + status + ") != 0");
  }
  return d;
}
 
开发者ID:jxtz518,项目名称:Tensorflow_Andriod_With_Audio_Output,代码行数:28,代码来源:TensorFlowYoloDetector.java

示例10: runModel

import org.tensorflow.contrib.android.TensorFlowInferenceInterface; //导入依赖的package包/类
public static  void runModel(AssetManager assetManager, String inputName, String[] outputNames, String modelFileName, ArrayList<Mat> imBox){
    TensorFlowInferenceInterface inferenceInterface = new TensorFlowInferenceInterface(assetManager,modelFileName);
    //final Operation operation = inferenceInterface.graphOperation(outputNames[0]);
    //final int numClasses = (int) operation.output(0).shape().size(1);
    //Mat mat = imBox.reshape(0,1);
    int l = imBox.get(0).width();
    int h = imBox.size();
    float[] FloatValues = new float[h*l];
    for(int i = 0; i < h; i++) {
        Mat mat = imBox.get(i);
        for (int j = 0; j < l; j++) {
            FloatValues[i * l + j] = (float) (255 - mat.get(0, j)[0]) / 255;
        }
    }
    inferenceInterface.feed(inputName,FloatValues,l,h);
    
    inferenceInterface.run(outputNames,logStat);
    int numClasses = 10;
    int[]output = new int[h];
    float[] layer = new float[h*numClasses];
    inferenceInterface.fetch(outputNames[0],output);
    //inferenceInterface.fetch(outputNames[1],layer);
    //inferenceInterface.fetch(outputNames[0],output[1]);
    for(int i = 0; i < 9; i++){
        for(int j = 0; j < 9; j++){
            RunModel.output[j][i] = output[i*9+j];
        }
    }

    RunModel.layer = layer;
}
 
开发者ID:Sanahm,项目名称:SudoCAM-Ku,代码行数:32,代码来源:RunModel.java

示例11: TensorFlowImageClassifier

import org.tensorflow.contrib.android.TensorFlowInferenceInterface; //导入依赖的package包/类
/**
 * Initializes a native TensorFlow session for classifying images.
 *
 * @param assetManager  The asset manager to be used to load assets.
 * @param modelFilename The filepath of the model GraphDef protocol buffer.
 * @param labelFilename The filepath of label file for classes.
 * @param numClasses    The number of classes output by the model.
 * @param inputSize     The input size. A square image of inputSize x inputSize is assumed.
 * @param imageMean     The assumed mean of the image values.
 * @param imageStd      The assumed std of the image values.
 * @param inputName     The label of the image input node.
 * @param outputName    The label of the output node.
 */
@SuppressWarnings("WeakerAccess")
public TensorFlowImageClassifier(AssetManager assetManager,
                                 String modelFilename,
                                 String labelFilename,
                                 int numClasses,
                                 int inputSize,
                                 int imageMean,
                                 float imageStd,
                                 String inputName,
                                 String outputName) {
    this.inputName = inputName;
    this.outputName = outputName;

    // Read the label names into memory.
    String actualFilename = labelFilename.split("file:///android_asset/")[1];

    this.labels = readLabels(assetManager, actualFilename);
    Log.i(TAG, "Read " + labels.size() + ", " + numClasses + " specified");

    this.inputSize = inputSize;
    this.imageMean = imageMean;
    this.imageStd = imageStd;

    // Pre-allocate buffers.
    this.outputNames = new String[]{outputName};
    this.floatValues = new float[inputSize * inputSize * 3];
    this.outputs = new float[numClasses];
    this.mBmpPixelValues = new int[inputSize * inputSize];

    this.mTensorFlowInferenceInterface = new TensorFlowInferenceInterface();
    this.mTensorFlowInferenceInterface.initializeTensorFlow(assetManager, modelFilename);
}
 
开发者ID:kevalpatel2106,项目名称:robo-car,代码行数:46,代码来源:TensorFlowImageClassifier.java

示例12: DrawViewOnTouchListener

import org.tensorflow.contrib.android.TensorFlowInferenceInterface; //导入依赖的package包/类
public DrawViewOnTouchListener(DrawView mDrawView, DrawModel mModel, TensorFlowInferenceInterface inferenceInterface, int numberToWrite, Context context) {
    this.mDrawView = mDrawView;
    this.mModel = mModel;
    this.inferenceInterface = inferenceInterface;
    this.numberToWrite = numberToWrite;
    this.context = context;
}
 
开发者ID:elimu-ai,项目名称:egma-handwriting-numbers,代码行数:8,代码来源:DrawViewOnTouchListener.java

示例13: initTensorFlowAndLoadModel

import org.tensorflow.contrib.android.TensorFlowInferenceInterface; //导入依赖的package包/类
private void initTensorFlowAndLoadModel() {
    Log.i(getClass().getName(), "initTensorFlowAndLoadModel");
    try {
        inferenceInterface = new TensorFlowInferenceInterface(getAssets(), MODEL_FILE);
        Log.d(getClass().getName(), "Load Success");
    } catch (final Exception e) {
        throw new RuntimeException("Error initializing TensorFlow!", e);
    }
}
 
开发者ID:elimu-ai,项目名称:egma-handwriting-numbers,代码行数:10,代码来源:WriteNumberActivity.java

示例14: TensorFlow

import org.tensorflow.contrib.android.TensorFlowInferenceInterface; //导入依赖的package包/类
public TensorFlow(Context context, int inputSize, int outputSize, String inputLayer, String outputLayer, String modelFile){
    this.inputSize = inputSize;
    this.outputSize = outputSize;
    this.inputLayer = inputLayer;
    this.outputLayer = outputLayer;

    inferenceInterface = new TensorFlowInferenceInterface(context.getAssets(), modelFile);
}
 
开发者ID:Qualeams,项目名称:Android-Face-Recognition-with-Deep-Learning-Library,代码行数:9,代码来源:TensorFlow.java

示例15: create

import org.tensorflow.contrib.android.TensorFlowInferenceInterface; //导入依赖的package包/类
/**
 * Initializes a native TensorFlow session for classifying images.
 *
 * @param assetManager The asset manager to be used to load assets.
 * @param modelFilename The filepath of the model GraphDef protocol buffer.
 * @param locationFilename The filepath of label file for classes.
 * @param inputSize The input size. A square image of inputSize x inputSize is assumed.
 * @param imageMean The assumed mean of the image values.
 * @param imageStd The assumed std of the image values.
 * @param inputName The label of the image input node.
 * @param outputName The label of the output node.
 */
public static Classifier create(
    final AssetManager assetManager,
    final String modelFilename,
    final String locationFilename,
    final int imageMean,
    final float imageStd,
    final String inputName,
    final String outputLocationsName,
    final String outputScoresName) {
  final TensorFlowMultiBoxDetector d = new TensorFlowMultiBoxDetector();

  d.inferenceInterface = new TensorFlowInferenceInterface(assetManager, modelFilename);

  final Graph g = d.inferenceInterface.graph();

  d.inputName = inputName;
  // The inputName node has a shape of [N, H, W, C], where
  // N is the batch size
  // H = W are the height and width
  // C is the number of channels (3 for our purposes - RGB)
  final Operation inputOp = g.operation(inputName);
  if (inputOp == null) {
    throw new RuntimeException("Failed to find input Node '" + inputName + "'");
  }
  d.inputSize = (int) inputOp.output(0).shape().size(1);
  d.imageMean = imageMean;
  d.imageStd = imageStd;
  // The outputScoresName node has a shape of [N, NumLocations], where N
  // is the batch size.
  final Operation outputOp = g.operation(outputScoresName);
  if (outputOp == null) {
    throw new RuntimeException("Failed to find output Node '" + outputScoresName + "'");
  }
  d.numLocations = (int) outputOp.output(0).shape().size(1);

  d.boxPriors = new float[d.numLocations * 8];

  try {
    d.loadCoderOptions(assetManager, locationFilename, d.boxPriors);
  } catch (final IOException e) {
    throw new RuntimeException("Error initializing box priors from " + locationFilename);
  }

  // Pre-allocate buffers.
  d.outputNames = new String[] {outputLocationsName, outputScoresName};
  d.intValues = new int[d.inputSize * d.inputSize];
  d.floatValues = new float[d.inputSize * d.inputSize * 3];
  d.outputScores = new float[d.numLocations];
  d.outputLocations = new float[d.numLocations * 4];

  return d;
}
 
开发者ID:apacha,项目名称:TensorflowAndroidDemo,代码行数:65,代码来源:TensorFlowMultiBoxDetector.java


注:本文中的org.tensorflow.contrib.android.TensorFlowInferenceInterface类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。