mtcnn-java icon indicating copy to clipboard operation
mtcnn-java copied to clipboard

RuntimeException: ERROR: Unable to set value configuration:Unparseable ConfigProto

Open mhashem opened this issue 7 years ago • 4 comments

Hello I am trying to use the library to do some Face detection experiments,

Here is my code

public class CNNPreprocessorClient implements IPreprocessorClient<byte[], List<BufferedImage>> {

	private static final Logger logger = getLogger(CNNPreprocessorClient.class);
	
	private MtcnnService mtcnnService;
	private Java2DNativeImageLoader imageLoader;
	
	public CNNPreprocessorClient() {
		this.mtcnnService = new MtcnnService(30, 0.709, new double[] { 0.6, 0.7, 0.7 });
		this.imageLoader = new Java2DNativeImageLoader();
	}

	@Override
	public List<BufferedImage> align(byte[] imageBytes) {
		List<BufferedImage> bufferedImages = Lists.newArrayList();
		try {
			INDArray originalImage = imageLoader.asMatrix(imageBytes).get(point(0), all(), all(), all()).dup();
			FaceAnnotation[] faceAnnotations = mtcnnService.faceDetection(originalImage);
			for (FaceAnnotation faceAnnotation : faceAnnotations) {
				INDArray alignedFace = mtcnnService.faceAlignment(originalImage, faceAnnotation, 44, 160, true);
				bufferedImages.add(imageLoader.asBufferedImage(alignedFace));
			}
			
		} catch (IOException e) {
			logger.error(e.getMessage(), e);
		}
		return bufferedImages;
	}

	@Override
	public List<FaceBox> detectFaces(byte[] imageBytes) {
		return null;
	}
	
	
}

and here is the pom file dependencies

<dependency>
			<groupId>net.tzolov.cv</groupId>
			<artifactId>mtcnn</artifactId>
			<version>0.0.4</version>
		</dependency>

		<dependency>
			<groupId>org.bytedeco.javacpp-presets</groupId>
			<artifactId>tensorflow-platform</artifactId>
			<version>1.11.0-1.4.3</version>
		</dependency>

and here is the error I am getting

java.lang.RuntimeException: ERROR: Unable to set value configuration:Unparseable ConfigProto

	at org.nd4j.tensorflow.conversion.graphrunner.GraphRunner.initSessionAndStatusIfNeeded(GraphRunner.java:313)
	at org.nd4j.tensorflow.conversion.graphrunner.GraphRunner.initSessionAndStatusIfNeeded(GraphRunner.java:330)
	at org.nd4j.tensorflow.conversion.graphrunner.GraphRunner.<init>(GraphRunner.java:176)
	at net.tzolov.cv.mtcnn.MtcnnService.createGraphRunner(MtcnnService.java:112)
	at net.tzolov.cv.mtcnn.MtcnnService.<init>(MtcnnService.java:97)
	at co.rxstack.ml.client.preprocessor.v2.CNNPreprocessorClient.<init>(CNNPreprocessorClient.java:28)
	at co.rxstack.ml.preprocessor.v2.CNNPreprocessorClientTest.setup(CNNPreprocessorClientTest.java:22)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

mhashem avatar Nov 16 '18 06:11 mhashem

@tzolov 😄 can you advise ?

mhashem avatar Nov 20 '18 21:11 mhashem

I encountered the same problem

zscgrhg avatar Nov 24 '18 04:11 zscgrhg

I‘m new to tensorflow. I'm not sure if it's the problem of operating system ,mine is windows 10. I successfully built the source code after some modifications:

MtcnnService.java line 105

replace ConfigProto.getDefaultInstance() with a custom ConfigProto ConfigProto cp = ConfigProto .newBuilder() .setInterOpParallelismThreads(4) .setAllowSoftPlacement(true) .setLogDevicePlacement(true) .build(); return new GraphRunner( IOUtils.toByteArray(new DefaultResourceLoader().getResource(tensorflowModelUri).getInputStream()), Arrays.asList(inputLabel), cp);

But then I ran into a new problem:

Exception in thread "main" java.lang.IllegalStateException: ERROR: Unable to run session Must specify at least one target to fetch or execute. at org.nd4j.tensorflow.conversion.graphrunner.GraphRunner.run(GraphRunner.java:525) at net.tzolov.cv.mtcnn.MtcnnService.preparationStage(MtcnnService.java:292) at net.tzolov.cv.mtcnn.MtcnnService.rawFaceDetection(MtcnnService.java:241) at net.tzolov.cv.mtcnn.MtcnnService.faceDetection(MtcnnService.java:170) at net.tzolov.cv.mtcnn.MtcnnService.faceDetection(MtcnnService.java:139) at net.tzolov.cv.mtcnn.sample.FaceDetectionSample1.main(FaceDetectionSample1.java:53)

At last

I get it worked by changes:

MtcnnService.java line 105

private GraphRunner createGraphRunner(String tensorflowModelUri, String inputLabel,String... outLabel) { try { ConfigProto cp = ConfigProto .newBuilder() .setInterOpParallelismThreads(4) .setAllowSoftPlacement(true) .setLogDevicePlacement(true) .build(); return new GraphRunner( IOUtils.toByteArray(new DefaultResourceLoader() .getResource(tensorflowModelUri) .getInputStream()), Arrays.asList(inputLabel),Arrays.asList(outLabel), cp); } catch (IOException e) { throw new IllegalStateException(String.format("Failed to load TF model [%s] and input [%s]:", tensorflowModelUri, inputLabel), e); } }

and:

MtcnnService.java line 94

`

    this.proposeNetGraphRunner = this.createGraphRunner(TF_PNET_MODEL_URI, "pnet/input","pnet/conv4-2/BiasAdd","pnet/prob1");
    this.refineNetGraphRunner = this.createGraphRunner(TF_RNET_MODEL_URI, "rnet/input","rnet/conv5-2/conv5-2","rnet/prob1");
    this.outputNetGraphRunner = this.createGraphRunner(TF_ONET_MODEL_URI, "onet/input","onet/conv6-2/conv6-2","onet/conv6-3/conv6-3",
            "onet/prob1"  );




  

`

zscgrhg avatar Nov 25 '18 04:11 zscgrhg

@zscgrhg I tried your solution, it worked 😄, however the unit tests @tzolov written differs a little bit in calculations

mhashem avatar Nov 26 '18 14:11 mhashem