- Explained: How Does L1 Regularization Perform Feature Selection?
- llama.cpp: Writing A Simple C++ Inference Program for GGUF LLM Models
- Building On-Device Face Recognition In Android
- From Python To Android: HF Sentence Transformers (Embeddings)
- On-Device Machine Learning In Android: Frameworks and Ecosystem
- Using C/C++ in Android: A Comprehensive Guide For Beginners
- [Building A Cross-Pl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ML Model to detect the age of a person, hosted on Heroku | |
class AgeDetectionModel { | |
private val herokuModelPredictURL = "https://age-detection-tf-app.herokuapp.com/predict" | |
private val mediaType = "application/json".toMediaType() | |
private val okHttpClient = OkHttpClient() | |
interface PredictionCallback { | |
fun onResult( age : Int ) | |
fun onError( error : String ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Detect faces in the given image and crop them. | |
// Pass the cropped faces to the AgeDetectionModel | |
private fun detectFaces(image: Bitmap) { | |
val inputImage = InputImage.fromBitmap(image, 0) | |
firebaseFaceDetector.process(inputImage) | |
.addOnSuccessListener { faces -> | |
if ( faces.size != 0 ) { | |
progressDialog.apply { | |
dismiss() | |
setMessage( "📍 Posting to server ...") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
implementation 'androidx.core:core-ktx:1.7.0' | |
implementation 'androidx.appcompat:appcompat:1.4.1' | |
implementation 'com.google.android.material:material:1.5.0' | |
implementation 'androidx.constraintlayout:constraintlayout:2.1.3' | |
// 1. MLKit Face Detection | |
implementation 'com.google.android.gms:play-services-mlkit-face-detection:17.0.0' | |
// 2. OkHttp is a HTTP client for Android |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private lateinit var activityMainBinding : ActivityMainBinding | |
private lateinit var progressDialog : ProgressDialog | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
activityMainBinding = ActivityMainBinding.inflate( layoutInflater ) | |
setContentView( activityMainBinding.root ) | |
progressDialog = ProgressDialog( this ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask , jsonify , request | |
from PIL import Image | |
import tensorflow as tf | |
import numpy as np | |
import base64 | |
import io | |
# Loading the Keras model to perform inference | |
# Download the model from this release -> | |
# https://github.com/shubham0204/Age-Gender_Estimation_TF-Android/releases/tag/v1.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import matplotlib.pyplot as plt | |
def poisson( lambda_ , x ): | |
return ( (lambda_)**x * math.exp(-lambda_) ) / math.factorial(x) | |
x = [] | |
y = [] | |
for i in range( 100 ): | |
x.append( i ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hidden_dims = 128 | |
token_mixing_mlp_dims = 64 | |
channel_mixing_mlp_dims = 128 | |
patch_size = 9 | |
num_classes = 10 | |
num_mixer_layers = 4 | |
input_image_shape = ( 32 , 32 , 3 ) | |
inputs = tf.keras.layers.Input( shape=input_image_shape ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hidden_dims = 128 | |
token_mixing_mlp_dims = 64 | |
channel_mixing_mlp_dims = 128 | |
patch_size = 9 | |
num_classes = 10 | |
num_mixer_layers = 4 | |
reshape_image_dim = 72 | |
input_image_shape = ( 32 , 32 , 3 ) | |
inputs = tf.keras.layers.Input( shape=input_image_shape ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Mixer layer consisting of token mixing MLPs and channel mixing MLPs | |
# input shape -> ( batch_size , channels , num_patches ) | |
# output shape -> ( batch_size , channels , num_patches ) | |
def mixer( x , token_mixing_mlp_dims , channel_mixing_mlp_dims ): | |
# inputs x of are of shape ( batch_size , num_patches , channels ) | |
# Note: "channels" is used instead of "embedding_dims" | |
# Add token mixing MLPs | |
token_mixing_out = token_mixing( x , token_mixing_mlp_dims ) | |
# Shape of token_mixing_out -> ( batch_size , channels , num_patches ) |