All Projects → OmarAflak → Keras-Android-XOR

OmarAflak / Keras-Android-XOR

Licence: other
How to run a Keras model on Android using Tensorflow API.

Programming Languages

java
68154 projects - #9 most used programming language
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Keras-Android-XOR

TPU-MobilenetSSD
Edge TPU Accelerator / Multi-TPU + MobileNet-SSD v2 + Python + Async + LattePandaAlpha/RaspberryPi3/LaptopPC
Stars: ✭ 82 (+156.25%)
Mutual labels:  tensorflow-lite
AgroDocRevamp
Agro Doc is basically an app that will help farmers easily pinpoint their crop diseases using their smartphones. The app uses a pre trained tensorflow model to identify issues and then suggest possible cures for the crop infections/diseases. #AndroidDevChallenge
Stars: ✭ 21 (-34.37%)
Mutual labels:  tensorflow-lite
Binary-Calculator-JavaScript
📱 A handy Calculator for Binary operations, that works on all Devices 📱 💻 🖥 | ⛓ https://play.google.com/store/apps/details?id=com.binarycalculator.ayidouble.binarycalculator.app ⛓
Stars: ✭ 45 (+40.63%)
Mutual labels:  xor
nntrainer
NNtrainer is Software Framework for Training Neural Network Models on Devices.
Stars: ✭ 92 (+187.5%)
Mutual labels:  tensorflow-lite
meta-st-stm32mpu-ai
This repository contains the OpenEmbedded meta layer to install AI frameworks and tools for the STM32MP1
Stars: ✭ 32 (+0%)
Mutual labels:  tensorflow-lite
glDelegateBenchmark
quick and dirty benchmark for TFLite gles delegate on iOS
Stars: ✭ 13 (-59.37%)
Mutual labels:  tensorflow-lite
Age-Gender Estimation TF-Android
Age + Gender Estimation on Android with TensorFlow Lite
Stars: ✭ 34 (+6.25%)
Mutual labels:  tensorflow-lite
coral-pi-rest-server
Perform inferencing of tensorflow-lite models on an RPi with acceleration from Coral USB stick
Stars: ✭ 49 (+53.13%)
Mutual labels:  tensorflow-lite
rpi-urban-mobility-tracker
The easiest way to count pedestrians, cyclists, and vehicles on edge computing devices or live video feeds.
Stars: ✭ 75 (+134.38%)
Mutual labels:  tensorflow-lite
Face-Recognition-Flutter
Realtime face recognition with Flutter
Stars: ✭ 111 (+246.88%)
Mutual labels:  tensorflow-lite
android tflite
GPU Accelerated TensorFlow Lite applications on Android NDK. Higher accuracy face detection, Age and gender estimation, Human pose estimation, Artistic style transfer
Stars: ✭ 105 (+228.13%)
Mutual labels:  tensorflow-lite
glDelegateBench
quick and dirty inference time benchmark for TFLite gles delegate
Stars: ✭ 17 (-46.87%)
Mutual labels:  tensorflow-lite
ipt xor
iptables xor module
Stars: ✭ 15 (-53.12%)
Mutual labels:  xor
face-detection-tflite
Face and iris detection for Python based on MediaPipe
Stars: ✭ 78 (+143.75%)
Mutual labels:  tensorflow-lite
tensorflow-vast
TensorFlow binding library for VA Smalltalk
Stars: ✭ 13 (-59.37%)
Mutual labels:  tensorflow-lite
oxorany
obfuscated any constant encryption in compile time on any platform
Stars: ✭ 155 (+384.38%)
Mutual labels:  xor
lua-simple-encrypt
Lua simple XOR encrypt
Stars: ✭ 60 (+87.5%)
Mutual labels:  xor
E2E-tfKeras-TFLite-Android
End to end training MNIST image classifier with tf.Keras, convert to TFLite and deploy to Android
Stars: ✭ 17 (-46.87%)
Mutual labels:  tensorflow-lite
CRNN.tf2
Convolutional Recurrent Neural Network(CRNN) for End-to-End Text Recognition - TensorFlow 2
Stars: ✭ 131 (+309.38%)
Mutual labels:  tensorflow-lite
TensorFlow Lite SSD RPi 64-bits
TensorFlow Lite SSD on bare Raspberry Pi 4 with 64-bit OS at 24 FPS
Stars: ✭ 25 (-21.87%)
Mutual labels:  tensorflow-lite

How to run a Keras model on Android

This code is a simple example to understand how to run a Keras model on Android using Tensorflow API.

Train the model on a computer

This is a super simple model that uses Keras to learn XOR operation :

index.py

X = np.array([[0,0],[0,1],[1,0],[1,1]])
Y = np.array([[0],[1],[1],[0]])

model = Sequential()
model.add(Dense(8, input_dim=2, activation='tanh'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer=SGD(lr=0.1))
model.fit(X, Y, batch_size=1, nb_epoch=1000)

run the python script :

python index.py

When done, the script should have created an out folder which contains several files. Among them, tensorflow_lite_xor_nn.pb, which is the model to export in Android assets folder.

Run the model on Android

MainActivity.java

public class MainActivity extends AppCompatActivity {
    private TensorFlowInferenceInterface inferenceInterface;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Load model from assets
        inferenceInterface = new TensorFlowInferenceInterface(getAssets(), "tensorflow_lite_xor_nn.pb");

        // run the model for all possible inputs i.e. [0,0], [0,1], [1,0], [1,1]
        for(int i=0 ; i<2 ; i++){
            for(int j=0 ; j<2 ; j++){
                float[] input = {i,j};
                float[] output = predict(input);

                Log.d(getClass().getSimpleName(), Arrays.toString(input)+" -> "+Arrays.toString(output));
            }
        }
    }

    private float[] predict(float[] input){
        // model has only 1 output neuron
        float output[] = new float[1];

        // feed network with input of shape (1,input.length) = (1,2)
        inferenceInterface.feed("dense_1_input", input, 1, input.length);
        inferenceInterface.run(new String[]{"dense_2/Sigmoid"});
        inferenceInterface.fetch("dense_2/Sigmoid", output);

        // return prediction
        return output;
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].