Skip to content

Commit

Permalink
Rename 'Reader's to 'Importer's
Browse files Browse the repository at this point in the history
Move reference data into nnabla-sample-data
  • Loading branch information
YukioOobuchi committed Jun 26, 2018
1 parent 8a79539 commit b13cbb5
Show file tree
Hide file tree
Showing 174 changed files with 305 additions and 483 deletions.
8 changes: 6 additions & 2 deletions build-tools/code_generator/functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,11 @@ Neural Network Layer:
GlobalAveragePooling:
snake_name: global_average_pooling
doc: |2
.. WARNING::
This function is experimental suppport, so please do not actively use it.
Global average pooling. It pools an averaged value from the whole image
inputs:
x:
doc: Input variable.
Expand Down Expand Up @@ -2163,6 +2165,8 @@ Array Manipulation:
BroadcastTo:
snake_name: broadcast_to
doc: |2
.. WARNING::
This function is experimental suppport, so please do not actively use it.
Broadcasting ND-array to the specified buffer.
inputs:
Expand Down Expand Up @@ -2295,7 +2299,7 @@ Stochasticity:
Dropout.
Samples a number :math:`u` from a uniform distribution in :math:`[0, 1]` ,
and ignores the input if :math:`u > p`.
and ignores the input if :math:`u \leq p`.
.. math::
y = \left\{
Expand Down
2 changes: 2 additions & 0 deletions doc/python/api/function.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Neural Network Layers
.. autofunction:: depthwise_deconvolution
.. autofunction:: max_pooling
.. autofunction:: average_pooling
.. autofunction:: global_average_pooling
.. autofunction:: sum_pooling
.. autofunction:: unpooling
.. autofunction:: embed
Expand Down Expand Up @@ -167,6 +168,7 @@ Array Manipulation
.. autofunction:: pad
.. autofunction:: transpose
.. autofunction:: broadcast
.. autofunction:: broadcast_to
.. autofunction:: flip
.. autofunction:: shift
.. autofunction:: reshape
Expand Down
3 changes: 2 additions & 1 deletion docker/development/Dockerfile.build.in
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ RUN umask 0 \
&& pip install --no-cache-dir -U -r /tmp/deps/test_requirements.txt \
&& pip install --no-cache-dir -U "pytest-pep8" \
&& pip install --no-cache-dir -U "pytest-cov" \
&& pip install --no-cache-dir -U "Cython<0.25"
&& pip install --no-cache-dir -U "Cython<0.25" \
&& pip install --no-cache-dir -U "numpy<1.11"

ENV PATH /opt/miniconda3/envs/{PYENVNAME}/bin:$PATH
7 changes: 5 additions & 2 deletions python/pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[pytest]
#addopts = -vv -s -x # Verbose output.
#addopts = -k "test_nnp or test_onnx" # ONNX converter only.
## Verbose output.
##addopts = -vv -s -x

## ONNX converter only.
#addopts = -k "test_nnp or test_onnx"
2 changes: 1 addition & 1 deletion python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Cython>=0.24,<0.26
boto3
h5py
numpy
numpy>=1.10
onnx
protobuf
pyyaml
Expand Down
4 changes: 0 additions & 4 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,6 @@ def extopts(library_name, library_dir):
'nnabla.utils.converter.nnablart',
'nnabla.utils.converter.onnx',
'nnabla.utils.factorization',
'nnabla.utils.converter',
'nnabla.utils.converter.nnabla',
'nnabla.utils.converter.nnablart',
'nnabla.utils.converter.onnx',
'nnabla_ext',
'nnabla_ext.cpu', ]

Expand Down
54 changes: 27 additions & 27 deletions python/src/nnabla/utils/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ def function_info_command(args):


def dump_command(args):
if 'read_format' in args:
if args.read_format not in nnabla.utils.converter.formats.read:
print('Read format ({}) is not supported.'.format(args.read_format))
if 'import_format' in args:
if args.import_format not in nnabla.utils.converter.formats.import_name:
print('Import format ({}) is not supported.'.format(args.import_format))
return
nnabla.utils.converter.dump_files(args, args.files)


def nnb_template_command(args):
if 'read_format' in args:
if args.read_format not in nnabla.utils.converter.formats.read:
print('Read format ({}) is not supported.'.format(args.read_format))
if 'import_format' in args:
if args.import_format not in nnabla.utils.converter.formats.import_name:
print('Import format ({}) is not supported.'.format(args.import_format))
return
if len(args.files) >= 2:
output = args.files.pop()
Expand All @@ -47,13 +47,13 @@ def nnb_template_command(args):

def convert_command(args):

if 'read_format' in args:
if args.read_format not in nnabla.utils.converter.formats.read:
print('Read format ({}) is not supported.'.format(args.read_format))
if 'import_format' in args:
if args.import_format not in nnabla.utils.converter.formats.import_name:
print('Import format ({}) is not supported.'.format(args.import_format))
return

if 'export_format' in args:
if args.export_format not in nnabla.utils.converter.formats.export:
if args.export_format not in nnabla.utils.converter.formats.export_name:
print('Export format ({}) is not supported.'.format(args.export_format))
return

Expand All @@ -63,8 +63,8 @@ def convert_command(args):


def add_convert_command(subparsers):
read_formats_string = ','.join(
nnabla.utils.converter.formats.read)
import_formats_string = ','.join(
nnabla.utils.converter.formats.import_name)

# Function Info
subparser = subparsers.add_parser(
Expand All @@ -78,23 +78,23 @@ def add_convert_command(subparsers):
'dump', help='Dump network with supported format.')
subparser.add_argument('files', metavar='FILE', type=str, nargs='+',
help='File or directory name(s) to convert.')
# read option
# import option
# NNP
subparser.add_argument('-I', '--read-format', type=str, default='NNP',
help='[read] read format. (one of [{}])'.format(read_formats_string))
subparser.add_argument('--nnp-expand-network', action='store_true',
help='[read][NNP] expand network with repeat or recurrent.')
subparser.add_argument('-I', '--import-format', type=str, default='NNP',
help='[import] import format. (one of [{}])'.format(import_formats_string))
subparser.add_argument('--nnp-no-expand-network', action='store_true',
help='[import][NNP] expand network with repeat or recurrent.')
subparser.set_defaults(func=dump_command)

# Generate NNB template
subparser = subparsers.add_parser(
'nnb_template', help='Generate NNB config file template.')
subparser.add_argument('files', metavar='FILE', type=str, nargs='+',
help='File or directory name(s) to convert.')
subparser.add_argument('-I', '--read-format', type=str, default='NNP',
help='[read] read format. (one of [{}])'.format(read_formats_string))
subparser.add_argument('--nnp-expand-network', action='store_true',
help='[read][NNP] expand network with repeat or recurrent.')
subparser.add_argument('-I', '--import-format', type=str, default='NNP',
help='[import] import format. (one of [{}])'.format(import_formats_string))
subparser.add_argument('--nnp-no-expand-network', action='store_true',
help='[import][NNP] expand network with repeat or recurrent.')
subparser.add_argument('-b', '--batch-size', type=int, default=-1,
help='[export] overwrite batch size.')
subparser.add_argument('-T', '--default-variable-type', type=str, nargs=1, default=['FLOAT32'],
Expand All @@ -105,15 +105,15 @@ def add_convert_command(subparsers):
subparser = subparsers.add_parser('convert', help='File format converter.')
subparser.add_argument('files', metavar='FILE', type=str, nargs='+',
help='File or directory name(s) to convert.')
# read option
# import option
# NNP
subparser.add_argument('-I', '--read-format', type=str, default='NNP',
help='[read] read format. (one of [{}])'.format(read_formats_string))
subparser.add_argument('--nnp-expand-network', action='store_true',
help='[read][NNP] expand network with repeat or recurrent.')
subparser.add_argument('-I', '--import-format', type=str, default='NNP',
help='[import] import format. (one of [{}])'.format(import_formats_string))
subparser.add_argument('--nnp-no-expand-network', action='store_true',
help='[import][NNP] expand network with repeat or recurrent.')
# export option
export_formats_string = ','.join(
nnabla.utils.converter.formats.export)
nnabla.utils.converter.formats.export_name)
subparser.add_argument('-O', '--export-format', type=str, default='NNP',
help='[export] export format. (one of [{}])'.format(export_formats_string))
subparser.add_argument('-f', '--force', action='store_true',
Expand Down
42 changes: 21 additions & 21 deletions python/src/nnabla/utils/converter/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
import os
import sys

from .nnabla import NnpReader, NnpExporter
from .nnabla import NnpImporter, NnpExporter
from .nnablart import NnbExporter, CsrcExporter
from .onnx import OnnxReader, OnnxExporter
from .onnx import OnnxImporter, OnnxExporter


def _read_nnp(args, ifiles):
def _import_nnp(args, ifiles):
if len(ifiles) == 1 and os.path.splitext(ifiles[0])[1] == '.nnp':
args.read_format = 'NNP'
args.import_format = 'NNP'
if len(ifiles) == 1 and os.path.splitext(ifiles[0])[1] == '.onnx':
args.read_format = 'ONNX'
if args.read_format == 'NNP':
args.import_format = 'ONNX'
if args.import_format == 'NNP':
# Input file that has unsuported extension store into output nnp archive or directory.
return NnpReader(*ifiles, expand_network=args.nnp_expand_network).read()
elif args.read_format == 'ONNX':
return OnnxReader(*ifiles).read()
return NnpImporter(*ifiles, expand_network=not args.nnp_no_expand_network).execute()
elif args.import_format == 'ONNX':
return OnnxImporter(*ifiles).execute()
return None


Expand All @@ -44,17 +44,17 @@ def _export_from_nnp(args, nnp, output):
parameter_type = 'h5'
if args.nnp_exclude_parameter:
parameter_type = 'none'
NnpExporter(nnp, args.batch_size, parameter_type).export(output)
NnpExporter(nnp, args.batch_size, parameter_type).execute(output)

elif output_ext == '.nnb':
NnbExporter(nnp, args.batch_size).export(
NnbExporter(nnp, args.batch_size).execute(
output, None, args.settings, args.default_variable_type)

elif os.path.isdir(output) and args.export_format == 'CSRC':
CsrcExporter(nnp, args.batch_size).export(output)
CsrcExporter(nnp, args.batch_size).execute(output)

elif output_ext == '.onnx':
OnnxExporter(nnp, args.batch_size).export(output)
OnnxExporter(nnp, args.batch_size).execute(output)
else:
print('Output file ({}) is not supported or output directory does not exist.'.format(
output_ext))
Expand All @@ -63,26 +63,26 @@ def _export_from_nnp(args, nnp, output):


def convert_files(args, ifiles, output):
nnp = _read_nnp(args, ifiles)
nnp = _import_nnp(args, ifiles)
if nnp is not None:
return _export_from_nnp(args, nnp, output)
else:
print('Read from [{}] failed.'.format(ifiles))
print('Import from [{}] failed.'.format(ifiles))
return False


def _generate_nnb_template(args, nnp, output):
NnbExporter(nnp, args.batch_size).export(
NnbExporter(nnp, args.batch_size).execute(
None, output, None, args.default_variable_type)
return True


def nnb_template(args, ifiles, output):
nnp = _read_nnp(args, ifiles)
nnp = _import_nnp(args, ifiles)
if nnp is not None:
return _generate_nnb_template(args, nnp, output)
else:
print('Read from [{}] failed.'.format(ifiles))
print('Import from [{}] failed.'.format(ifiles))
return False


Expand All @@ -109,14 +109,14 @@ def _dump_protobuf(proto, prefix, depth):


def _dump_nnp(args, nnp):
_dump_protobuf(nnp.protobuf, [args.read_format], -1)
_dump_protobuf(nnp.protobuf, [args.import_format], -1)
return True


def dump_files(args, ifiles):
nnp = _read_nnp(args, ifiles)
nnp = _import_nnp(args, ifiles)
if nnp is not None:
return _dump_nnp(args, nnp)
else:
print('Read from [{}] failed.'.format(ifiles))
print('Import from [{}] failed.'.format(ifiles))
return False
62 changes: 0 additions & 62 deletions python/src/nnabla/utils/converter/convert_files.py

This file was deleted.

8 changes: 6 additions & 2 deletions python/src/nnabla/utils/converter/functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,11 @@ Neural Network Layer:
GlobalAveragePooling:
snake_name: global_average_pooling
doc: |2
.. WARNING::
This function is experimental suppport, so please do not actively use it.
Global average pooling. It pools an averaged value from the whole image
inputs:
x:
doc: Input variable.
Expand Down Expand Up @@ -2163,6 +2165,8 @@ Array Manipulation:
BroadcastTo:
snake_name: broadcast_to
doc: |2
.. WARNING::
This function is experimental suppport, so please do not actively use it.
Broadcasting ND-array to the specified buffer.
inputs:
Expand Down Expand Up @@ -2291,7 +2295,7 @@ Stochasticity:
Dropout.
Samples a number :math:`u` from a uniform distribution in :math:`[0, 1]` ,
and ignores the input if :math:`u > p`.
and ignores the input if :math:`u \leq p`.
.. math::
y = \left\{
Expand Down
2 changes: 1 addition & 1 deletion python/src/nnabla/utils/converter/nnabla/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .reader import NnpReader
from .importer import NnpImporter
from .exporter import NnpExporter

0 comments on commit b13cbb5

Please sign in to comment.