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

Unclear Intermediate Layer Implementation in find_adversarial_example #145

Closed
ace-shifu opened this issue Nov 8, 2023 · 2 comments
Closed

Comments

@ace-shifu
Copy link

Hello, I am very interested in your project, but after reading the source code of find_adversarial_example, I found that only input constraints and related output constraints are shown to be set. However, intermediate layers such as affine and ReLU layers are not explicitly called. How do you call these methods from the layers directory in find_adversarial_example to accomplish intermediate layer encoding?

@vtjeng
Copy link
Owner

vtjeng commented Nov 8, 2023

Hi @ace-shifu -- thanks for your interest.

Here's an example where you specify the neural network:

nn = Sequential(
[
Flatten(4),
Linear(l1_kernel, l1_bias),
MaskedReLU(m1),
Linear(l2_kernel, l2_bias),
MaskedReLU(m2),
Linear(l3_kernel, l3_bias),
],
"tests.integration.generated_weights.mfc+mfc+softmax",
)

Let's start by taking a look at the Sequential struct:

struct Sequential <: NeuralNet
layers::Array{Layer,1}
UUID::String
end
function Base.show(io::IO, p::Sequential)
println(io, "sequential net $(p.UUID)")
for (index, value) in enumerate(p.layers)
println(io, " ($index) $value")
end
end
(p::Sequential)(x::Array{<:JuMPReal}) = x |> p.layers

The key chunk of code is the last line, where we defined p(x) = x |> p.layers (the equivalent of p.layers(x) in other programming languages).

Now, here's the important bit: x can either be a number or a JuMPLinearType:

JuMPLinearType = Union{JuMP.VariableRef,JuMP.AffExpr}

If x is a JuMPLinearType, then the output p(x) is also a JuMPLinearType, with the appropriate constraints imposed between the input and output. (This is what the output constraints are imposed on).

Feel free to reach out if you have more questions.

@ace-shifu
Copy link
Author

Thank you for your patient response. My issue has been resolved.

@vtjeng vtjeng closed this as completed Nov 10, 2023
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