Comments (3)
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.
from nnabla.
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:
# print(nnp.get_network_names())
['Main', 'MainValidation', 'MainRuntime']
# print(x)
<Variable((1, 28, 28), need_grad=False) at 0x11e7a6728>
# print(y)
{'Sigmoid': <Variable((1, 1), need_grad=True) at 0x11e7a6638>}
If I'm using Main or MainValidation network, output is below.
# print(x)
<Variable((1, 28, 28), need_grad=False) at 0x11a08c818>
# print(y)
{'BinaryCrossEntropy': <Variable((1, 1), need_grad=True) at 0x11a08c728>}
I can't find out variable x and y from graph.inputs
and graph.outputs
looks like sample code. And I don't know what is Nnp
method.
# Read a .nnp file.
nnp = Nnp('/path/to/nnp.nnp')
# Assume a graph `graph_a` is in the nnp file.
net = nnp.get_network(network_name, batch_size=1)
# `x` is an input of the graph.
x = net.inputs['x']
# 'y' is an outputs of the graph.
y = net.outputs['y']
# Set random data as input and perform forward prop.
x.d = np.random.randn(x.shape)
y.forward(clear_buffer=True)
print('output:', y.d)
https://nnabla.readthedocs.io/en/latest/_modules/nnabla/utils/nnp_graph.html
I have attached my nnp file.
Thanks.
from nnabla.
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)
from nnabla.
Related Issues (20)
- Add support to release linux aarch64 wheels HOT 8
- No module named "win32com" HOT 2
- Example DeeplabV3 not works HOT 3
- segmentaion fault occurs in convolution(group=in_channel) during mixed precision training
- import nnabla_ext.cuda - ImportError: libcudart.so.11.0: cannot open shared object file: No such file or directory HOT 35
- Does nnabla support Nvidia Tesla T4 GPU? HOT 2
- Error when exporting model to onnx HOT 3
- 3.10 PYPI binary wheels HOT 2
- Partially initialized module HOT 2
- Strange import behavior, OSError libllvmlite.so HOT 1
- cannot import nnabla in `numpy==1.21.4` and `nnabla>=1.29.0` HOT 9
- Citation outdated HOT 3
- Converting onnx to nnp opset version error HOT 2
- Feature Request: Converting nnp -> nnb using c++ libraries HOT 1
- Error: "pip install nnabla" on M1(M2)mac HOT 4
- Installation module built on Ubuntu fails HOT 2
- Wrong behavior of top_k_data() with cuda HOT 3
- Header for the std::isalpha() function. HOT 1
- Can I use nbla::Array in a extenstion created by C Python API? HOT 1
- Cannot install via Pip neither Miniconda. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nnabla.