Skip to content

Instantly share code, notes, and snippets.

View shubham0204's full-sized avatar
🎯
Focusing

Shubham Panchal shubham0204

🎯
Focusing
View GitHub Profile
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 )
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
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 )
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 )
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 )
# 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 )
# Channel Mixing MLPs : Allow communication within channels ( features of embeddings )
def channel_mixing( x , channel_mixing_mlp_dims ):
# x is a tensor of shape ( batch_size , num_patches , channels )
x = tf.keras.layers.LayerNormalization( epsilon=1e-6 )( x )
x = mlp( x , channel_mixing_mlp_dims )
return x
# Token Mixing MLPs : Allow communication within patches.
def token_mixing( x , token_mixing_mlp_dims ):
# x is a tensor of shape ( batch_size , num_patches , channels )
x = tf.keras.layers.LayerNormalization( epsilon=1e-6 )( x )
x = tf.keras.layers.Permute( dims=[ 2 , 1 ] )( x )
# After transposition, shape of x -> ( batch_size , channels , num_patches )
x = mlp( x , token_mixing_mlp_dims )
return x
# Multilayer Perceptron with GeLU ( Gaussian Linear Units ) activation
def mlp( x , hidden_dims ):
y = tf.keras.layers.Dense( hidden_dims )( x )
y = tf.nn.gelu( y )
y = tf.keras.layers.Dense( x.shape[ -1 ] )( y )
y = tf.keras.layers.Dropout( 0.4 )( y )
return y