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

An error with optimizeGraph function #50

Closed
damdaepark opened this issue Jun 19, 2019 · 2 comments
Closed

An error with optimizeGraph function #50

damdaepark opened this issue Jun 19, 2019 · 2 comments

Comments

@damdaepark
Copy link

damdaepark commented Jun 19, 2019

I found that optimizeGraph function occurs a problem when it is used with workspaceNames function.
Under certain circumstances, it seems that optimizeGraph negates original layers' names defined by workspaceNames function.

Below is the simplified code that can reproduce the error.
You can run it section-wise, and it will generate the error in the second section.

clear all; clc;

%% Error doesn't occur
S = Input('name','S');

loss_A = sum((S-1).^2,1);
loss_B = sum((S-2).^2,1);
loss_T = mean(loss_A + loss_B, 2);

Layer.workspaceNames();

myNet = Net(loss_T);
myNet.eval({'S',10});
find(contains({myNet.forward.name},'loss_A'))
myNet.getValue('loss_A')

%% Error occurs
% It can be fixed when we configure [opts.optimizeGraph = false] in the function [@Net\compile], or when we put ( - ) sign into the sum function.

S = Input('name','S');

loss_A = - sum((S-1).^2,1);
loss_B = - sum((S-2).^2,1);
loss_T = mean(loss_A + loss_B, 2);

Layer.workspaceNames();

myNet = Net(loss_T);
myNet.eval({'S',10});
find(contains({myNet.forward.name},'loss_A'))
myNet.getValue('loss_A')

As I described on the code, the error can be fixed with either by configuring opts.optimizeGraph = false in the function @net\compile, or by migrating the - signs into the inside of the sum functions.

But it would be a clearer solution that we retain the original layer name by putting some additional lines in the optimizeGraph function.

@jotaf98
Copy link
Collaborator

jotaf98 commented Jun 19, 2019

You're right, the optimization can be quite aggressive!

It's difficult to know automatically whether your code will want to refer to a layer later, or not (in which case it can be optimized away).

You can ask for autonn to not optimize away a layer with:

loss_A.optimize = False

@damdaepark
Copy link
Author

That's a nice solution. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants