-
Notifications
You must be signed in to change notification settings - Fork 32
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
Importing my own neural network for verification #13
Comments
Hi @UserAlreadyTaken --- I'm not certain what you're trying to do here. 1. If you'd just like to work with an example neural network, you can do so using the function
The supported options are documented here: MIPVerify.jl/src/utils/import_example_nets.jl Lines 8 to 24 in cff0581
2. If you'd like to understand how to extracting weights saved in a checkpoint and saving it to a Feel free to provide a link to an example neural network you're trying to verify and I might be able to provide more specific suggestions. Alternatively, it would also help if you described the structure of your network! |
https://nbviewer.jupyter.org/github/vtjeng/MIPVerify.jl/blob/master/examples/01_importing_your_own_neural_net.ipynb In your tutorials you said that We'll download a .mat file containing the parameters of a sample neural net containing three layers (exported from tensorflow). But I find that there is no tensorflow API for save network weight as a .mat file. And we train a network using tensorflow then save the weight into a .h5 file. |
Ah, sorry for the lack of clarity --- I'll fix that in the next release. As you pointed out, there is no tensorflow API for saving network weights as a Instead, you can use the Sorry this is inconvenient. I'm open to feedback (or a pull request!) for how it can be made better. [1] this example code could be useful. |
I have another problem, before verify network, you must use nn=Sequential([]), but I do not know how to express maxpool layer, what's the parameters of MaxPool(), I just use (0,2,2,1), and then when use MIPVerify.frac_correct(), it report the ERROR: InexactError()...orz..., |
If you're looking for a pooling layer with a height and width of 2x2, the parameters you want are (just in case, this is the source code for the pool layer) If possible, I would suggest skipping the max pooling layer if you're running into timeouts during verification since it adds a large number of binary variables; instead, you could use a convolution with a stride of 2. |
emmmm, I'm sorry about I have to ask for your help again. |
No worries --- thank you for asking all these questions. I believe that
More generally, I would consider following the code here: which shows how we take a neural net from a |
Flatten([1, 3, 2, 4]) does not work..., and I experiment with that all 24 orders of permutation, |
The error message below shows the issue: it appears that the output from
your last convolution layer is the wrong size, since after flattening the
output from this layer you have a vector of size 1024, while the fully
connected layer had an expected input of 400 (and 120 output channels).
Perhaps you're missing a pooling layer or something.
ERROR: DimensionMismatch("matrix A has dimensions (120,400), vector B has
length 1024")
My best debugging advice is to check the size of the output as you add
layers to the network by passing in a sample input of the right size (if
you're working with MNIST, for example, use a 28x28 input).
|
I'm sure that I'm missing no layer, I used example provided by official website.
and in pytorch like this:
in convert.py:
I think the problem may occur to different between x.view(-1, 400) , x.view(x.size(0), -1) and Flatten([1,3,2,4]) in MIPVerify. |
It looks like your neural network is using the "valid" padding for convolutions, rather than the "same" padding that is the default for the MIPVerify code. "valid" padding is currently unimplemented in my package, but I can get it implemented sometime soon. In the meantime, you can consider using "same" padding --- this should be realtively straightforward to do. padding="same"
padding="valid"
[a] I'm using the notation for convolution padding in https://keras.io/layers/convolutional/ |
I imported my network successfully, but when I verifying I imported the network correctly, the accuracy rate is just 0.0917... somewhere was gong wrong... when testing network, the accuracy rate is 0.69
another network I tried has same problem, the accuracy rate should be 0.72, but in MIPVerify, it is 0.09 |
That looks like you're getting the accuracy of random guessing. Here's one thing to try: When working with convolution layers from Pytorch, I found that transposing the tensor is necessary because pytorch and Julia have different conventions.
A full example is below: I'm planning to fix this: #14 but in the meantime can you try transposing when you export the weights? |
ah, I have imported my network correctly. Verification has taken me 2days and has no result. It's normal that it cost for a long time? and the next step I want to verify residual network, could you tell me how to import a residual network? thanks a lot! |
Do you mean for a single sample? That is unexpectedly long. I'd be happy to dig deeper into your issue if you provide me the logs from the solver. For resnets, we use the skip unit, mirroring the implementation in Wong et. al.. Here is an example of verification of one of their networks, with the weights already extracted in
|
yep, it's a single sample. It has no more log, the network is the one I asked all the time.
Calculating upper bounds and lower bounds.......................for two days. |
Hi @UserAlreadyTaken --- these were the log outputs from the solver I was referring to --- thank you for sharing them. I am surprised that it is taking so long. What size of perturbations are you trying to verify robustness to? |
The size of perturbations I haven;t thought about it yet. The parameter of MIPVerify are default, I just have try....I didn't expect it to take so long.
|
And it has more log outputs from solver, as following:
it seems like it's going to keep calculating....... |
Hi --- this call to To fully take advantage of the approach, I would advocate that you specify the range of perturbations that you're searching in. For example, if you're searching over a l-infinity ball of size eps=0.01, you would do the following.
It also makes a difference whether you're trying to find the minimal adversarial example or just some adversarial example within a given distance. Let me know what you're trying to do and I can give you a bit more advice. |
ok, I will try to specify the range of perturbations. What I'm trying to do is that learning how to verify robustness of neural network. I am a student and I'm studying this research. By the way, can I have you other contact information like Wechat or anyothers, it will be more convenient to get advice from you, thanks! |
Closing as there has not been any activity on this issue for more than 90 days --- feel free to re-open if there are any additional questions. |
I have questions that seem to fit this thread. My neural network is in an h5 file and I want to convert it to .mat by Matlab. First, do you think this is a good way to do this and if not, what would you do? Second, I know for your conversion where you started with pytorch, you saved your nn in a dictionary. Assuming I'm using Matlab, which should I use: structures or containers? Thank you. |
Hi @ksilken, saw that you had a follow-up question in #36, so perhaps you've already addressed these issues. Anyway --- If I were doing this personally, I would use Python but only because that's what I'm most familiar with. (I haven't used Matlab in a long time). If you succeeded at using Matlab, would you share whether you used structures or containers for other people coming across this thread? |
I'm studying your tool now, and I want to import my own network for verification, but I do not know how to get .mat file. Your example shows that exported from tensorflow, but how? And my own network has no bias or Adam_1 like your example(fc1/bias). Or could say I can not obtain it from my network.
could you tell me how to get a .mat file(anywhere can download or how to create by myself)?
The text was updated successfully, but these errors were encountered: