Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error using TransferLearningHelper with TinyYOLO #4635

Closed
nlebreton opened this issue Feb 8, 2018 · 6 comments

Comments

@nlebreton
Copy link

commented Feb 8, 2018

Hi

By calling the following code:

TinyYOLO model = new TinyYOLO(nClasses, seed);
ComputationGraph computationGraph = (ComputationGraph) model.initPretrained();
TransferLearningHelper transferLearningHelper = new TransferLearningHelper(computationGraph, "conv2d_9");

We get the following exception stacktrace:

Exception in thread "main" org.nd4j.linalg.exception.ND4JIllegalStateException: Invalid shape: Requested INDArray shape [1, 0] contains dimension size values < 1 (all dimensions must be 1 or more)
at org.nd4j.linalg.factory.Nd4j.checkShapeValues(Nd4j.java:5122)
at org.nd4j.linalg.factory.Nd4j.create(Nd4j.java:5112)
at org.nd4j.linalg.factory.Nd4j.create(Nd4j.java:5065)
at org.nd4j.linalg.factory.Nd4j.create(Nd4j.java:4170)
at org.deeplearning4j.nn.graph.ComputationGraph.init(ComputationGraph.java:452)
at org.deeplearning4j.nn.graph.ComputationGraph.init(ComputationGraph.java:377)
at org.deeplearning4j.nn.transferlearning.TransferLearning$GraphBuilder.build(TransferLearning.java:755)
at org.deeplearning4j.nn.transferlearning.TransferLearningHelper.initHelperGraph(TransferLearningHelper.java:252)
at org.deeplearning4j.nn.transferlearning.TransferLearningHelper.(TransferLearningHelper.java:56)
at nlb.ai.deeplearning.dl4j.image.objectdetection.PersonsDetection.main(PersonsDetection.java:39)

It works perfectly well with VGG16.

  • Deeplearning4j version 0.9.2-SANPSHOT
  • windows 10
  • neither CUDA nor NVIDIA are used
@saudet

This comment has been minimized.

@AlexDBlack

This comment has been minimized.

Copy link
Contributor

commented Feb 9, 2018

The problem is that there's no actual trainable parameters in your network configuration, as the whole network is frozen (using that constructor). Which is obviously bad, as you can't learn anything if all your parameters are frozen.

I'll leave this open, as it should have a more useful exception, at the very least.

@AlexDBlack

This comment has been minimized.

Copy link
Contributor

commented Feb 9, 2018

As discussed in gitter: this is actually probably a legitimate thing to do: i.e., if the goal is to save a featurized dataset (which it is here).

@AlexDBlack AlexDBlack added the Bug label Feb 9, 2018

@AlexDBlack

This comment has been minimized.

Copy link
Contributor

commented Feb 9, 2018

Workaround:

  TinyYOLO model2 = new TinyYOLO(nClasses, seed);
        ComputationGraph computationGraph2 = (ComputationGraph) model2.initPretrained();
        log.info(computationGraph2.summary());

        ComputationGraph transfer = new TransferLearning.GraphBuilder(computationGraph2)
                .removeVertexAndConnections("outputs")
                .addLayer("outputs", new OutputLayer.Builder().nOut(10).build(), "conv2d_9")
                .setOutputs("outputs")
                .setInputTypes(InputType.convolutional(416, 416, 3))
                .build();

        TransferLearningHelper transferLearningHelper2 = new TransferLearningHelper(transfer, "conv2d_9");

        System.out.println(transferLearningHelper2.unfrozenGraph().summary());

Reason for the bug: subset of the network after the frozen layer doesn't have any parameters (hence fails during initialization). This is why nets such as VGG (with an OutputLayer) work but this one doesn't.

AlexDBlack added a commit that referenced this issue Feb 16, 2018
AlexDBlack added a commit that referenced this issue Feb 16, 2018
Merge pull request #4664 from deeplearning4j/ab_zeroparamnets
Add support for zero-param nets & fix #4635
@AlexDBlack

This comment has been minimized.

Copy link
Contributor

commented Feb 16, 2018

Thanks for reporting - confirmed fixed (with test) here: #4664

@lock

This comment has been minimized.

Copy link

commented Sep 23, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Sep 23, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants
You can’t perform that action at this time.