I’m implementing face recognition and clustering software in iOS, For that first I’ve detected faces from picture and cropped face photographs utilizing MLKit, That works nicely.
Now I’m giving cropped face photographs in face recognition machine studying fashions utilizing tensorflow lite to get vectors for face.
However On this second step, I get identical output for all face photographs, Thus far I’ve tried three totally different variations of facenet machine studying fashions.
Beneath is the code to initialise machine studying mannequin:
init() throws {
do {
// Initialize an interpreter with the mannequin.
interpreter = strive Interpreter(modelPath: modelPath)
// Allocate reminiscence for the mannequin's enter `Tensor`s.
strive interpreter.allocateTensors()
// Get enter particulars
let inputDetails = strive interpreter.enter(at: 0)
inputWidth = inputDetails.form.dimensions[1]
inputHeight = inputDetails.form.dimensions[2]
// Print enter form
print("Enter Form: (inputDetails.form), inputWidth: (inputWidth), inputHeight: (inputHeight)")
} catch {
throw error
}
}
Beneath is the code to course of cropped face photographs:
func generateVectors(photographs: [UIImage]) {
do {
for picture in photographs {
guard let resizedImage = picture.resized(to: CGSize(width: inputWidth, peak: inputHeight)),
let inputData = resizedImage.normalizedData() else {
print("Did not course of picture")
proceed
}
// Feed information to mannequin
strive interpreter.copy(inputData, toInputAt: 0)
// Run inference
strive interpreter.invoke()
// Get output
let outputTensor = strive interpreter.output(at: 0)
// Convert uncooked Knowledge to Float32 array
let floatArray = outputTensor.information.withUnsafeBytes {
Array(UnsafeBufferPointer(
begin: $0.baseAddress?.assumingMemoryBound(to: Float32.self),
depend: outputTensor.form.dimensions[1] // 128 values
))
}
print("Characteristic Vector Output: (floatArray)")
}
} catch let error {
print("Error operating mannequin: (error)")
}
return output
}
Beneath is the output vectors:
[-0.009220079, 0.038770936, 0.01804376, 0.0017266792, -0.06855814, 0.07214466, -0.06875174, -0.06868738, -0.09033966, -0.01930608, -0.0195967, 0.011521962, -0.008457049, 0.03948402, -0.002224167, -0.058808904, -0.030869633, -0.009765219, 0.000973374, 0.0037677472, -0.19366269, 0.08309283, -0.047775332, 0.016188627, 0.02456835, 0.01125063, -0.05468251, 0.08173297, 0.19266018, -0.059302196, -0.01258643, 0.28976113, 0.09724123, 0.002565295, -0.0486573, 0.10080463, -0.026181312, -0.014548875, 0.0027476046, -0.010945596, 0.009463895, 0.005252799, 0.019287268, -0.009135995, 0.008196506, -0.0612358, 0.009160928, 0.004444012, -0.010797426, 0.06427721, 0.0635613, -0.00705058, -0.23729105, -0.0038941011, -0.021929592, 0.0070061935, 0.007189498, 0.0051750448, -0.1103151, 0.034162432, 0.038976744, -0.13650523, -0.050892524, 0.04492468, -0.016929258, 0.017758325, -0.007822959, 0.019677926, 0.00964872, 0.0012666954, -0.044016927, -0.034723878, -0.08498321, 0.012788337, -0.041820418, 0.009875813, 0.003703687, -0.0010015147, 0.2554124, 0.046859697, -0.008996924, 0.028291812, -0.0138691915, 0.197871, -0.08906104, -0.003602797, -0.00471391, -0.009401287, 0.040403757, -0.14449984, 0.015253428, -0.0011967644, 0.012509383, -0.029001027, -0.017686743, -0.15465711, -0.010484967, 0.006724833, -0.0010327495, 0.004064801, 0.0033183543, -0.0161573, -0.008383467, -0.00051657186, -0.0041507203, 0.0070093162, -0.17482482, 0.0017419434, -0.005793525, 0.022245506, -0.1609532, 0.012124289, 0.012564862, 0.27895862, 0.013894456, 0.06850863, -0.003990949, -0.045771595, 0.11117715, 0.11178145, 0.15556717, -0.017600833, -0.15439847, -0.0024967825, 0.002401842, -0.0032675255, 0.0061577093, -0.001042465, -0.0018741376, -0.116546564, 0.014505089, 0.030642524, -0.00013455506, -0.00610297, 0.07161295, -0.014800259, -0.18568702, -0.010711309, 0.009508076, 0.012341375, -0.005046241, 0.0009768148, -0.0007504827, -0.057355925, -0.089514, 0.07412282, -0.020803858, -0.0035957384, 0.009036027, -0.01416573, -0.011037713, -0.1024432, -0.0001064163, -0.034000482, -0.0112722535, -0.002430556, 0.005671933, 0.009195163, -0.13230675, -0.0062144296, -0.07031675, -0.0019532659, -0.015630726, 0.0007332002, 0.005727988, 0.024316145, 0.02418903, -0.09510416, -0.006006736, -0.00040619334, 0.18963154, 0.032816295, -0.0025780753, -0.013093517, 0.02123824, 0.005748838, -0.089399874, -0.0964007, -0.0134110255, 0.010199679, -0.07981146, -0.03332103, 0.00030683028, -0.0036552714, 0.16836038, 0.02386042, -0.11319512, 0.10237385, 0.11490546, -0.06683481, -0.083391674, -0.013886787]
I’m not including a number of output right here, as a result of they’re identical and I do not need to add them pointless.
I doubt there may be some subject with processing cropped face photographs, As I’ve tried three totally different machine studying fashions, and I’m dealing with identical subject with all of them.
One of many facenet mannequin I’m utilizing I took from this code:
https://github.com/njordsir/Clustering-faces-android
All the machine studying fashions are giving totally different outputs in contrast to one another, however all of them are giving identical output for each enter picture.
Thanks upfront!