exadel-inc / CompreFace

Leading free and open-source face recognition system
https://exadel.com/accelerator-showcase/compreface/
Apache License 2.0
5.7k stars 775 forks source link

mobilenet 1.1.0 not working with double-take #1073

Open pierluigizagaria opened 1 year ago

pierluigizagaria commented 1 year ago

double-take works fine using compreface-core:1.1.0 but gives error when using compreface-core:1.1.0-mobilenet

When using compreface-core:1.1.0-mobilenet compreface-api returns error 400

172.18.0.9 - - [23/May/2023:10:03:07 +0000] "POST /api/v1/recognition/recognize?face_plugins=undefined&det_prob_threshold=0.8 HTTP/1.1" 400 83 "-" "axios/0.27.2"

and compreface-api returns

2023-05-23 10:02:58.618 ERROR 7 --- [nio-8080-exec-9] c.e.f.c.h.ResponseExceptionHandler       : Undefined exception occurred
java.lang.IllegalStateException: Cannot perform operation "subi" - shapes are not equal and are not broadcastable.first.shape=[1, 512], second.shape=[128]
        at org.nd4j.common.base.Preconditions.throwStateEx(Preconditions.java:641)
        at org.nd4j.common.base.Preconditions.checkState(Preconditions.java:376)
        at org.nd4j.linalg.api.shape.Shape.assertBroadcastable(Shape.java:265)
        at org.nd4j.linalg.api.ndarray.BaseNDArray.subi(BaseNDArray.java:3238)
        at org.nd4j.linalg.api.ndarray.BaseNDArray.subi(BaseNDArray.java:3225)
        at com.exadel.frs.core.trainservice.component.classifiers.EuclideanDistanceClassifier.euclidean_distance(EuclideanDistanceClassifier.java:147)
        at com.exadel.frs.core.trainservice.component.classifiers.EuclideanDistanceClassifier.recognize(EuclideanDistanceClassifier.java:130)
        at com.exadel.frs.core.trainservice.component.classifiers.EuclideanDistanceClassifier.predict(EuclideanDistanceClassifier.java:58)
        at com.exadel.frs.core.trainservice.component.FaceClassifierPredictor.predict(FaceClassifierPredictor.java:34)
        at com.exadel.frs.core.trainservice.service.FaceRecognizeProcessServiceImpl.processFaceResult(FaceRecognizeProcessServiceImpl.java:72)
        at com.exadel.frs.core.trainservice.service.FaceRecognizeProcessServiceImpl.processImage(FaceRecognizeProcessServiceImpl.java:62)
        at com.exadel.frs.core.trainservice.service.FaceRecognizeProcessServiceImpl.processImage(FaceRecognizeProcessServiceImpl.java:26)
        at com.exadel.frs.core.trainservice.controller.RecognizeController.recognize(RecognizeController.java:75)
        at com.exadel.frs.core.trainservice.controller.RecognizeController$$FastClassBySpringCGLIB$$52b4c4f5.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
        at org.springframework.validation.beanvalidation.MethodValidationInterceptor.invoke(MethodValidationInterceptor.java:123)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708)
        at com.exadel.frs.core.trainservice.controller.RecognizeController$$EnhancerBySpringCGLIB$$75461a8.recognize(<generated>)
        at jdk.internal.reflect.GeneratedMethodAccessor127.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:681)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at com.exadel.frs.core.trainservice.filter.SecurityValidationFilter.doFilter(SecurityValidationFilter.java:134)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:96)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
        at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.base/java.lang.Thread.run(Unknown Source)

while compreface-core seems to work fine

{"severity": "DEBUG", "message": "Found: BoundingBoxDTO(x_min=214, y_min=193, x_max=350, y_max=395, probability=0.9944502115249634, _np_landmarks=array([[270.41437, 271.6983 ],\n       [327.2149 , 273.5742 ],\n       [308.94156, 315.77658],\n       [270.04153, 344.64978],\n       [316.96872, 346.79092]], dtype=float32))", "request": {"method": "POST", "path": "/find_faces", "filename": "lenna.jpg", "api_key": "", "remote_addr": "172.18.0.6"}, "logger": "src.services.facescan.plugins.insightface.insightface", "module": "insightface", "traceback": null, "build_version": "dev"}
{"severity": "INFO", "message": "200 OK", "request": {"method": "POST", "path": "/find_faces", "filename": "lenna.jpg", "api_key": "", "remote_addr": "172.18.0.6"}, "logger": "src.services.flask_.log_response", "module": "log_response", "traceback": null, "build_version": "dev"}
thinkjk commented 1 year ago

I'm seeing the exact same issue

pospielov commented 1 year ago

Sorry, somehow, I didn't see this post before. The reason is that the default build and custom builds are not compatible. Neural networks return the vectors of different sizes, so we can't calculate the similarity of faces that are stored in different builds. So you need to start with a clear database. The easiest way is to put docker compose config in a folder with a different name. By default, the release archive contains custom builds that are stored in folders with different names, so if you just open the folder and run 'docker compose up' in them, it should work

thinkjk commented 1 year ago

@pospielov thanks for the reply. I'm only seeing this issue with mobilenet when I tested with SubCenter-ArcFace-r100 I don't have this issue and double-take is able to connect. I only keep settings when switching between builds.

pospielov commented 1 year ago

Great, so we know the problem. In my previous response, I explained the steps to initiate CompreFace using a clean database. Feel free to let me know if you encounter any difficulties with this process.

namniav commented 1 year ago

@pospielov I tried the clean mobilenet 1.2.0 by running from the preset custom-builds/Mobilenet folder and saw same logs from compreface-api .

I built my custom compreface-core image to use non-CUDA non-AVX mxnet library (by specifying 'mxnet==1.9.1' here as mentioned in this comment). I also added a single rule to this [Makefile]() to only build mobilenet. Other images were pulled from hub.docker.com by docker compose up.

Then I visited the web-UI and clicked "Try Demo". When I uploaded a picture with no face, compreface returned No face is found in the given image successfully. But when I uploaded a picture with face, compreface returned Something went wrong, please try again.

compreface-api logs:

compreface-api  | 2023-11-08 08:42:42.529 ERROR 7 --- [nio-8080-exec-3] c.e.f.c.h.ResponseExceptionHandler       : Undefined exception occurred
compreface-api  | 
compreface-api  | java.lang.IllegalStateException: Cannot perform operation "subi" - shapes are not equal and are not broadcastable.first.shape=[20, 512], second.shape=[128]
compreface-api  |   at org.nd4j.common.base.Preconditions.throwStateEx(Preconditions.java:641)
compreface-api  |   at org.nd4j.common.base.Preconditions.checkState(Preconditions.java:376)
compreface-api  |   at org.nd4j.linalg.api.shape.Shape.assertBroadcastable(Shape.java:265)
compreface-api  |   at org.nd4j.linalg.api.ndarray.BaseNDArray.subi(BaseNDArray.java:3238)
compreface-api  |   at org.nd4j.linalg.api.ndarray.BaseNDArray.subi(BaseNDArray.java:3225)
compreface-api  |   at com.exadel.frs.core.trainservice.component.classifiers.EuclideanDistanceClassifier.euclidean_distance(EuclideanDistanceClassifier.java:147)
compreface-api  |   at com.exadel.frs.core.trainservice.component.classifiers.EuclideanDistanceClassifier.recognize(EuclideanDistanceClassifier.java:130)
compreface-api  |   at com.exadel.frs.core.trainservice.component.classifiers.EuclideanDistanceClassifier.predict(EuclideanDistanceClassifier.java:58)
compreface-api  |   at com.exadel.frs.core.trainservice.component.FaceClassifierPredictor.predict(FaceClassifierPredictor.java:34)
compreface-api  |   at com.exadel.frs.core.trainservice.service.FaceRecognizeProcessServiceImpl.processFaceResult(FaceRecognizeProcessServiceImpl.java:82)
compreface-api  |   at com.exadel.frs.core.trainservice.service.FaceRecognizeProcessServiceImpl.processImage(FaceRecognizeProcessServiceImpl.java:72)
compreface-api  |   at com.exadel.frs.core.trainservice.service.FaceRecognizeProcessServiceImpl.processImage(FaceRecognizeProcessServiceImpl.java:25)
compreface-api  |   at com.exadel.frs.core.trainservice.controller.RecognizeController.recognize(RecognizeController.java:113)
compreface-api  |   at com.exadel.frs.core.trainservice.controller.RecognizeController$$FastClassBySpringCGLIB$$52b4c4f5.invoke(<generated>)
compreface-api  |   at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
compreface-api  |   at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793)
compreface-api  |   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
compreface-api  |   at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
compreface-api  |   at org.springframework.validation.beanvalidation.MethodValidationInterceptor.invoke(MethodValidationInterceptor.java:123)
compreface-api  |   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
compreface-api  |   at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763)
compreface-api  |   at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708)
compreface-api  |   at com.exadel.frs.core.trainservice.controller.RecognizeController$$EnhancerBySpringCGLIB$$f9daa919.recognize(<generated>)
compreface-api  |   at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
compreface-api  |   at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
compreface-api  |   at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
compreface-api  |   at java.base/java.lang.reflect.Method.invoke(Unknown Source)
compreface-api  |   at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
compreface-api  |   at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150)
compreface-api  |   at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117)
compreface-api  |   at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
compreface-api  |   at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
compreface-api  |   at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
compreface-api  |   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067)
compreface-api  |   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
compreface-api  |   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
compreface-api  |   at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
compreface-api  |   at javax.servlet.http.HttpServlet.service(HttpServlet.java:681)
compreface-api  |   at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
compreface-api  |   at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
compreface-api  |   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
compreface-api  |   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
compreface-api  |   at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
compreface-api  |   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
compreface-api  |   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
compreface-api  |   at com.exadel.frs.core.trainservice.filter.SecurityValidationFilter.doFilter(SecurityValidationFilter.java:134)
compreface-api  |   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
compreface-api  |   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
compreface-api  |   at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
compreface-api  |   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
compreface-api  |   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
compreface-api  |   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
compreface-api  |   at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
compreface-api  |   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
compreface-api  |   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
compreface-api  |   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
compreface-api  |   at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:96)
compreface-api  |   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
compreface-api  |   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
compreface-api  |   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
compreface-api  |   at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
compreface-api  |   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117)
compreface-api  |   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
compreface-api  |   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
compreface-api  |   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
compreface-api  |   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
compreface-api  |   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541)
compreface-api  |   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
compreface-api  |   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
compreface-api  |   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
compreface-api  |   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:360)
compreface-api  |   at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:399)
compreface-api  |   at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
compreface-api  |   at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:890)
compreface-api  |   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1743)
compreface-api  |   at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
compreface-api  |   at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
compreface-api  |   at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
compreface-api  |   at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
compreface-api  |   at java.base/java.lang.Thread.run(Unknown Source)
compreface-api  |
namniav commented 1 year ago

I also tried mobilenet from release archive without any changes. Same behavior.