<commit_before>/* Copyright 2016 <NAME> and <NAME>. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

package ch.zhaw.facerecognitionlibrary.Recognition;

import android.content.res.AssetManager;
import android.graphics.Bitmap;

import org.opencv.android.Utils;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
import org.opencv.utils.Converters;

import java.util.ArrayList;
import java.util.List;

import ch.zhaw.facerecognitionlibrary.FaceRecognitionLibrary;
import ch.zhaw.facerecognitionlibrary.Helpers.FileHelper;
import ch.zhaw.facerecognitionlibrary.Helpers.PreferencesHelper;

/***************************************************************************************
 *    Title: TensorFlowAndroidDemo
 *    Author: miyosuda
 *    Date: 23.04.2016
 *    Code version: -
 *    Availability: https://github.com
 *
 ***************************************************************************************/

public class TensorFlow implements Recognition {
    private static final String STRING_SPLIT_CHARACTER = " ";

    private String inputLayer;
    private String outputLayer;

    private int inputSize;
    private int outputSize;

    Recognition rec;

    public TensorFlow(int method) {
        String dataPath = FileHelper.TENSORFLOW_PATH;
        inputSize = PreferencesHelper.getTensorFlowInputSize();
        int imageMean = PreferencesHelper.getTensorFlowImageMean();
        outputSize = PreferencesHelper.getTensorFlowOutputSize();
        inputLayer = PreferencesHelper.getTensorFlowInputLayer();
        outputLayer = PreferencesHelper.getTensorFlowOutputLayer();
        String modelFile = PreferencesHelper.getTensorFlowModelFile();
        Boolean classificationMethod = PreferencesHelper.getClassificationMethodTFCaffe();

        initializeTensorflow(FaceRecognitionLibrary.assets, dataPath + modelFile, inputSize, imageMean);

        if(classificationMethod){
            rec = new SupportVectorMachine(method);
        }
        else {
            rec = new KNearestNeighbor(method);
        }
    }

    // link jni library
    static {<commit_msg>Add new TensorFlow constructor to pass parameters<commit_after>/* Copyright 2016 <NAME> and <NAME>. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

package ch.zhaw.facerecognitionlibrary.Recognition;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;

import org.opencv.android.Utils;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
import org.opencv.utils.Converters;

import java.util.ArrayList;
import java.util.List;

import ch.zhaw.facerecognitionlibrary.FaceRecognitionLibrary;
import ch.zhaw.facerecognitionlibrary.Helpers.FileHelper;
import ch.zhaw.facerecognitionlibrary.Helpers.PreferencesHelper;

/***************************************************************************************
 *    Title: TensorFlowAndroidDemo
 *    Author: miyosuda
 *    Date: 23.04.2016
 *    Code version: -
 *    Availability: https://github.com
 *
 ***************************************************************************************/

public class TensorFlow implements Recognition {
    private static final String STRING_SPLIT_CHARACTER = " ";

    private String inputLayer;
    private String outputLayer;

    private int inputSize;
    private int outputSize;

    Recognition rec;

    public TensorFlow(int method) {
        String dataPath = FileHelper.TENSORFLOW_PATH;
        inputSize = PreferencesHelper.getTensorFlowInputSize();
        int imageMean = PreferencesHelper.getTensorFlowImageMean();
        outputSize = PreferencesHelper.getTensorFlowOutputSize();
        inputLayer = PreferencesHelper.getTensorFlowInputLayer();
        outputLayer = PreferencesHelper.getTensorFlowOutputLayer();
        String modelFile = PreferencesHelper.getTensorFlowModelFile();
        Boolean classificationMethod = PreferencesHelper.getClassificationMethodTFCaffe();

        initializeTensorflow(FaceRecognitionLibrary.assets, dataPath + modelFile, inputSize, imageMean);

        if(classificationMethod){
            rec = new SupportVectorMachine(method);
        }
        else {
            rec = new KNearestNeighbor(method);
        }
    }

    public TensorFlow(Context context, String dataPath, int inputSize, int imageMean, int outputSize, String inputLayer, String outputLayer, String modelFile){
        this.inputSize = inputSize;
        this.outputSize = outputSize;
        this.inputLayer = inputLayer;
        this.outputLayer = outputLayer;

        initializeTensorflow(context.getAssets(), modelFile, inputSize, imageMean);
    }

    // link jni library
    static {
{'fraction_non_alphanumeric': 0.15474974463738508, 'fraction_numerical': 0.005447735784814436, 'mean_word_length': 4.321557971014493, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1465387', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1434, 'n_words': 411}