-
Notifications
You must be signed in to change notification settings - Fork 334
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
How to get or use network from nnp #233
Comments
I can use the nnp file like below. def image():
:
x = nn.Variable((1,1,28,28))
x.d = np.array(img) * (1.0 / 255.0)
y = network(x, test=True)
y.forward()
:
def network(x, test=False):
# Input:x -> 1,28,28
# MaxPooling -> 1,14,14
h = F.max_pooling(x, (2,2), (2,2))
# Affine -> 100
h = PF.affine(h, (100,), name='Affine')
# ReLU
h = F.relu(h, True)
# Affine_2
h = PF.affine(h, (1,), name='Affine_2')
# Sigmoid
h = F.sigmoid(h)
return h But I think I don't need to write network method if I'm using nnp file. 'cause it is contained network by protocol buffer. |
This is NOT completely code. import nnabla as nn
import nnabla.functions as F
import nnabla.parametric_functions as PF
from nnabla.utils import nnp_graph
nnp = nnp_graph.NnpLoader('./result.nnp')
print(nnp.get_network_names())
graph = nnp.get_network('MainRuntime', batch_size=1)
x = graph.inputs['Input'][0]
print(x)
y = graph.outputs
print(y) Output:
If I'm using Main or MainValidation network, output is below.
I can't find out variable x and y from
https://nnabla.readthedocs.io/en/latest/_modules/nnabla/utils/nnp_graph.html I have attached my nnp file. Thanks. |
I did it. from nnabla.utils import nnp_graph
import numpy as np
from PIL import Image
nnp = nnp_graph.NnpLoader('./result.nnp')
graph = nnp.get_network('MainRuntime', batch_size=1)
# Input variable name
input = list(graph.inputs.keys())[0]
# Output variable name
output = list(graph.outputs.keys())[0]
# Get input and output
x = graph.inputs[input]
y = graph.outputs[output]
# Open image
img = Image.open('001.png')
# Transform
x.d = np.array(img) * (1.0 / 255.0)
# Forward
y.forward(clear_buffer=True)
print(y.d) |
Hi.
Neural Network Console of Windows provides h5 file and Python code. And Cloud version provides just nnp file. I know the nnp file has h5 and network of protocol buffers. But I don't know how to use network in nnp file.
Usally we can get the python code like below.
And we don't neet
BinaryCrossEntropy
, so delete it. The nnp file's network has it.This code outputs below.
I hope use the nnp in Python like below.
How to use network in the nnp file?
I know nnabla_cli can do it. But I don't know how to do it.
Thanks
The text was updated successfully, but these errors were encountered: