Comments (4)
@gowthami77, have you modified any variables in FaceNetModel.kt
? Like imgSize
or embeddingDim
?
from facerecognition_with_facenet_android.
No, I was not changed anything
This is my file
// Utility class for FaceNet model
class FaceNetModel( context : Context ) {
// TFLiteInterpreter used for running the FaceNet model.
private var interpreter : Interpreter
// Input image size for FaceNet model.
private val imgSize = 112
// Output embedding size
private val embeddingDim = 192
// Image Processor for preprocessing input images.
private val imageTensorProcessor = ImageProcessor.Builder()
.add( ResizeOp( imgSize , imgSize , ResizeOp.ResizeMethod.BILINEAR ) )
.add( NormalizeOp( 127.5f , 127.5f ) )
.build()
init {
// Initialize TFLiteInterpreter
val interpreterOptions = Interpreter.Options().apply {
setNumThreads( 4 )
}
interpreter = Interpreter(FileUtil.loadMappedFile(context, "facenet_int8.tflite") , interpreterOptions )
}
// Gets an face embedding using FaceNet, use the `crop` rect.
fun getFaceEmbedding( image : Bitmap , crop : Rect , preRotate: Boolean ) : FloatArray {
return runFaceNet(
convertBitmapToBuffer(
cropRectFromBitmap( image , crop , preRotate )
)
)[0]
}
// Gets an face embedding using the FaceNet model, given the cropped images.
fun getFaceEmbeddingWithoutBBox( image : Bitmap ) : FloatArray {
return runFaceNet( convertBitmapToBuffer( image ) )[0]
}
// Run the FaceNet model.
private fun runFaceNet(inputs: Any): Array<FloatArray> {
val t1 = System.currentTimeMillis()
val outputs = Array(1) { FloatArray(embeddingDim ) }
interpreter.run(inputs, outputs)
Log.i( "Performance" , "FaceNet Inference Speed in ms : ${System.currentTimeMillis() - t1}")
return outputs
}
// Resize the given bitmap and convert it to a ByteBuffer
private fun convertBitmapToBuffer( image : Bitmap) : ByteBuffer {
val imageTensor = imageTensorProcessor.process( TensorImage.fromBitmap( image ) )
Log.e("bitmap after",imageTensor.toString());
return imageTensor.buffer
}
// Crop the given bitmap with the given rect.
private fun cropRectFromBitmap(source: Bitmap, rect: Rect , preRotate : Boolean ): Bitmap {
var width = rect.width()
var height = rect.height()
if ( (rect.left + width) > source.width ){
width = source.width - rect.left
}
if ( (rect.top + height ) > source.height ){
height = source.height - rect.top
}
val croppedBitmap = Bitmap.createBitmap(
if ( preRotate ) rotateBitmap( source )!! else source,
rect.left,
rect.top,
width,
height )
Log.e("cropped bitmap","");
// saveBitmap( croppedBitmap , "image111")
return croppedBitmap
}
private fun saveBitmap(image: Bitmap, name: String) {
val fileOutputStream =
FileOutputStream(File( Environment.getExternalStorageDirectory()!!.absolutePath + "/$name.png"))
image.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream)
}
private fun rotateBitmap(source: Bitmap): Bitmap? {
val matrix = Matrix()
matrix.postRotate( -90f )
return Bitmap.createBitmap(source, 0, 0, source.width, source.height, matrix , false )
}
}
can you please help me to resolve this issue. It was very important to me.
from facerecognition_with_facenet_android.
@gowthami77, you need to change the model's file path, as well as imgSize
and embeddingDim
like,
// Utility class for FaceNet model
class FaceNetModel( context : Context ) {
// TFLiteInterpreter used for running the FaceNet model.
private var interpreter : Interpreter
// Input image size for FaceNet model.
private val imgSize = 160
// Output embedding size
private val embeddingDim = 128
// Image Processor for preprocessing input images.
private val imageTensorProcessor = ImageProcessor.Builder()
.add( ResizeOp( imgSize , imgSize , ResizeOp.ResizeMethod.BILINEAR ) )
.add( NormalizeOp( 127.5f , 127.5f ) )
.build()
init {
// Initialize TFLiteInterpreter
val interpreterOptions = Interpreter.Options().apply {
setNumThreads( 4 )
}
interpreter = Interpreter(FileUtil.loadMappedFile(context, "facenet_int8.tflite") , interpreterOptions )
}
This seems to be a bug, but I'll fix it in 2/3 days, as I have to make some other modifications as well. These changes will come in the next commit. Also, please verify if these changes are helpful.
from facerecognition_with_facenet_android.
it works. Thanks for the fix.
from facerecognition_with_facenet_android.
Related Issues (20)
- [Error] : Getting facelist.size as 0 in FrameAnalyser.kt HOT 12
- l2 Norm not working as expected. HOT 13
- I am getting same name for every image in the frame HOT 6
- [request] write detection log to a file
- [issue] Always assign a face even if the image does not exist. HOT 2
- How to train the facenet model HOT 2
- Works incorrectly in samsung A21s HOT 9
- Device orientation problem HOT 3
- bounding box overlay not showing properly. HOT 1
- Internal error: Failed to apply delegate with GpuDelegate HOT 3
- App is hanging with 300 Images HOT 3
- TfLiteGpuDelegate Invoke: GpuDelegate must run on the same thread HOT 3
- Multiple facial recognition in a single frameis not detecting properly HOT 2
- Access denied finding property "ro.mediatek.platform"! HOT 6
- Works on phone but not on tablet HOT 1
- How to improve the accuracy of facenet ?
- Can the source of the photo not be from storage but from a photo link? HOT 2
- landscape orientation HOT 2
- Application of tflite models and how to convert them. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from facerecognition_with_facenet_android.