提交 62fa59c9 authored 作者: Brandon T. Willard's avatar Brandon T. Willard

Apply isort to theano.tensor.nnet sub-package modules

上级 b90a5388
import warnings
from . import opt
from .abstract_conv import conv2d as abstract_conv2d
from .abstract_conv import conv2d_grad_wrt_inputs, conv3d, separable_conv2d
from .bn import batch_normalization
from .conv import ConvOp
from .nnet import ( from .nnet import (
CrossentropyCategorical1Hot, CrossentropyCategorical1Hot,
CrossentropyCategorical1HotGrad, CrossentropyCategorical1HotGrad,
...@@ -10,8 +17,8 @@ from .nnet import ( ...@@ -10,8 +17,8 @@ from .nnet import (
SoftmaxGrad, SoftmaxGrad,
SoftmaxWithBias, SoftmaxWithBias,
binary_crossentropy, binary_crossentropy,
sigmoid_binary_crossentropy,
categorical_crossentropy, categorical_crossentropy,
confusion_matrix,
crossentropy_categorical_1hot, crossentropy_categorical_1hot,
crossentropy_categorical_1hot_grad, crossentropy_categorical_1hot_grad,
crossentropy_softmax_1hot, crossentropy_softmax_1hot,
...@@ -22,6 +29,7 @@ from .nnet import ( ...@@ -22,6 +29,7 @@ from .nnet import (
crossentropy_softmax_max_and_argmax_1hot_with_bias, crossentropy_softmax_max_and_argmax_1hot_with_bias,
crossentropy_to_crossentropy_with_softmax, crossentropy_to_crossentropy_with_softmax,
crossentropy_to_crossentropy_with_softmax_with_bias, crossentropy_to_crossentropy_with_softmax_with_bias,
elu,
graph_merge_softmax_with_crossentropy_softmax, graph_merge_softmax_with_crossentropy_softmax,
h_softmax, h_softmax,
logsoftmax, logsoftmax,
...@@ -30,35 +38,24 @@ from .nnet import ( ...@@ -30,35 +38,24 @@ from .nnet import (
prepend_1_to_each_row, prepend_1_to_each_row,
prepend_scalar_to_each_row, prepend_scalar_to_each_row,
relu, relu,
selu,
sigmoid_binary_crossentropy,
softmax, softmax,
softmax_grad, softmax_grad,
softmax_graph, softmax_graph,
softmax_op, softmax_op,
softmax_simplifier, softmax_simplifier,
softmax_with_bias, softmax_with_bias,
elu,
selu,
confusion_matrix,
softsign, softsign,
) )
from . import opt
from .conv import ConvOp
from .sigm import ( from .sigm import (
softplus, hard_sigmoid,
scalar_sigmoid,
sigmoid, sigmoid,
sigmoid_inplace, sigmoid_inplace,
scalar_sigmoid, softplus,
ultra_fast_sigmoid, ultra_fast_sigmoid,
hard_sigmoid,
) )
from .bn import batch_normalization
import warnings
from .abstract_conv import conv2d as abstract_conv2d
from .abstract_conv import conv2d_grad_wrt_inputs
from .abstract_conv import conv3d
from .abstract_conv import separable_conv2d
def conv2d( def conv2d(
......
...@@ -4,27 +4,33 @@ Abstract conv interface ...@@ -4,27 +4,33 @@ Abstract conv interface
import logging import logging
from six import reraise, integer_types
import sys import sys
from six import integer_types, reraise
try: try:
from math import gcd from math import gcd
except ImportError: except ImportError:
from fractions import gcd from fractions import gcd
import theano import warnings
from theano.tensor import as_tensor_variable, patternbroadcast import numpy as np
from theano.tensor import get_scalar_constant_value, NotScalarConstantError
from theano.tensor.opt import Assert
from theano.gof import Apply, Op
import theano
from theano.gof import Apply, Op
from theano.tensor.basic import (
NotScalarConstantError,
as_tensor_variable,
get_scalar_constant_value,
patternbroadcast,
)
from theano.tensor.opt import Assert
import warnings
import numpy as np
try: try:
from scipy.signal.signaltools import _valfrommode, _bvalfromboundary, convolve from scipy.signal.signaltools import _bvalfromboundary, _valfrommode, convolve
from scipy.signal.sigtools import _convolve2d from scipy.signal.sigtools import _convolve2d
imported_scipy_signal = True imported_scipy_signal = True
......
import numpy as np import numpy as np
import theano import theano
from theano import Op, Apply from theano.gof.graph import Apply
from theano.tensor import discrete_dtypes from theano.gof.op import Op
from theano.gradient import grad_undefined from theano.gradient import grad_undefined
from theano.tensor.basic import discrete_dtypes
class SparseBlockGemv(Op): class SparseBlockGemv(Op):
......
import numpy as np import numpy as np
import theano import theano
from theano.gof.graph import Apply
# import theano.tensor.basic as tt from theano.gof.op import Op
from theano.gof.opt import copy_stack_trace, local_optimizer
from theano import Apply, Op
from theano.gof import local_optimizer
from theano.gof.opt import copy_stack_trace
from theano.scalar import Composite, add, as_common_dtype, mul, sub, true_div from theano.scalar import Composite, add, as_common_dtype, mul, sub, true_div
# Work-around for Python 3.6 issue that prevents `import theano.tensor as tt` # Work-around for Python 3.6 issue that prevents `import theano.tensor as tt`
from theano.tensor import basic as tt from theano.tensor import basic as tt
from theano.tensor import TensorType, as_tensor_variable from theano.tensor.basic import as_tensor_variable
from theano.tensor.elemwise import Elemwise from theano.tensor.elemwise import Elemwise
from theano.tensor.opt import register_specialize_device from theano.tensor.opt import register_specialize_device
from theano.tensor.type import TensorType
class BNComposite(Composite): class BNComposite(Composite):
......
...@@ -10,27 +10,27 @@ See especially conv2d(). ...@@ -10,27 +10,27 @@ See especially conv2d().
import logging import logging
import warnings
import numpy as np import numpy as np
import warnings
import theano import theano
from theano import OpenMPOp from theano.gof.graph import Apply
from theano.tensor import ( from theano.gof.op import OpenMPOp
from theano.tensor import blas
from theano.tensor.basic import (
NotScalarConstantError,
as_tensor_variable, as_tensor_variable,
blas,
get_scalar_constant_value, get_scalar_constant_value,
patternbroadcast, patternbroadcast,
NotScalarConstantError,
) )
from theano.gof import Apply
from theano.tensor.nnet.abstract_conv import get_conv_output_shape, get_conv_shape_1axis from theano.tensor.nnet.abstract_conv import get_conv_output_shape, get_conv_shape_1axis
try: try:
# TODO: move these back out to global scope when they no longer # TODO: move these back out to global scope when they no longer
# cause an atexit error # cause an atexit error
from scipy.signal.signaltools import _valfrommode, _bvalfromboundary from scipy.signal.signaltools import _bvalfromboundary, _valfrommode
from scipy.signal.sigtools import _convolve2d from scipy.signal.sigtools import _convolve2d
imported_scipy_signal = True imported_scipy_signal = True
......
import theano import theano
from theano.gradient import DisconnectedType
from theano.gof import Op, Apply, TopoOptimizer
from theano.gof.opt import copy_stack_trace
from theano import tensor from theano import tensor
from theano.gof import Apply, Op, TopoOptimizer
from theano.gof.opt import copy_stack_trace
from theano.gradient import DisconnectedType
def get_diagonal_subtensor_view(x, i0, i1): def get_diagonal_subtensor_view(x, i0, i1):
......
import os
import logging import logging
import os
from six import integer_types from six import integer_types
import theano import theano
from theano import Apply
from theano import gof from theano import gof
from theano.gof import ParamsType, EnumList from theano.gof.graph import Apply
from theano.scalar import int64, int8 from theano.gof.params_type import ParamsType
from theano.tensor import as_tensor_variable, TensorType from theano.gof.type import EnumList
from theano.tensor.nnet.abstract_conv import get_conv_output_shape from theano.scalar import int8, int64
from theano.tensor import blas_headers from theano.tensor import blas_headers
from theano.tensor.blas import ldflags, blas_header_version from theano.tensor.basic import as_tensor_variable
from theano.tensor.blas import blas_header_version, ldflags
from theano.tensor.nnet.abstract_conv import get_conv_output_shape
from theano.tensor.type import TensorType
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
......
import os
import logging import logging
import os
from six import integer_types from six import integer_types
import theano import theano
from theano import Apply
from theano import gof from theano import gof
from theano.gof import ParamsType, EnumList from theano.gof.graph import Apply
from theano.gof.params_type import ParamsType
from theano.gof.type import EnumList
from theano.scalar import int64 from theano.scalar import int64
from theano.tensor import as_tensor_variable, TensorType
from theano.tensor.nnet.abstract_conv import get_conv_output_shape
from theano.tensor import blas_headers from theano.tensor import blas_headers
from theano.tensor.blas import ldflags, blas_header_version from theano.tensor.basic import as_tensor_variable
from theano.tensor.blas import blas_header_version, ldflags
from theano.tensor.nnet.abstract_conv import get_conv_output_shape
from theano.tensor.type import TensorType
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
......
...@@ -2,7 +2,6 @@ import os ...@@ -2,7 +2,6 @@ import os
import sys import sys
import theano.tensor as tt import theano.tensor as tt
from theano import config, gof from theano import config, gof
from theano.gof import local_optimizer from theano.gof import local_optimizer
from theano.gof.cmodule import GCC_compiler from theano.gof.cmodule import GCC_compiler
......
...@@ -6,7 +6,6 @@ import numpy as np ...@@ -6,7 +6,6 @@ import numpy as np
import theano import theano
import theano.tensor as tt import theano.tensor as tt
from theano import Apply, Op from theano import Apply, Op
from theano.gof import EnumList from theano.gof import EnumList
from theano.gradient import grad_not_implemented, grad_undefined from theano.gradient import grad_not_implemented, grad_undefined
......
...@@ -17,35 +17,29 @@ import logging ...@@ -17,35 +17,29 @@ import logging
import warnings import warnings
import numpy as np import numpy as np
import theano
# import theano.tensor.basic as tt
import theano
from theano import scalar from theano import scalar
from theano.compile import optdb from theano.compile import optdb
from theano.gof.graph import Apply from theano.gof.graph import Apply
from theano.gof.op import Op from theano.gof.op import Op
from theano.gof.opt import copy_stack_trace, local_optimizer, optimizer
from theano.gradient import DisconnectedType, grad_not_implemented
from theano.scalar import UnaryScalarOp
# Work-around for Python 3.6 issue that prevents `import theano.tensor as tt` # Work-around for Python 3.6 issue that prevents `import theano.tensor as tt`
from theano.tensor import basic as tt from theano.tensor import basic as tt
from theano.tensor import extra_ops, opt, subtensor
from theano.tensor.basic import MaxAndArgmax, as_tensor_variable, log
from theano.tensor.elemwise import Elemwise
from theano.tensor.nnet.blocksparse import sparse_block_dot
from theano.tensor.nnet.sigm import sigmoid, softplus
from theano.tensor.opt import ( from theano.tensor.opt import (
register_canonicalize,
register_specialize, register_specialize,
register_stabilize, register_stabilize,
register_canonicalize,
) )
from theano.gof.opt import (
optimizer,
copy_stack_trace,
local_optimizer,
)
from theano.gradient import DisconnectedType, grad_not_implemented
from theano.scalar import UnaryScalarOp
from theano.tensor import as_tensor_variable, extra_ops, opt, subtensor
from theano.tensor.elemwise import Elemwise
from theano.tensor.subtensor import AdvancedSubtensor from theano.tensor.subtensor import AdvancedSubtensor
from theano.tensor.basic import log, MaxAndArgmax
from theano.tensor.nnet.blocksparse import sparse_block_dot
from theano.tensor.nnet.sigm import sigmoid, softplus
from theano.tensor.type import values_eq_approx_remove_inf, values_eq_approx_remove_nan from theano.tensor.type import values_eq_approx_remove_inf, values_eq_approx_remove_nan
......
...@@ -5,38 +5,33 @@ Optimizations addressing the ops in nnet root directory ...@@ -5,38 +5,33 @@ Optimizations addressing the ops in nnet root directory
import theano import theano
from theano import compile, gof from theano import compile, gof
from theano.compile import optdb from theano.compile import optdb
from theano.gof import local_optimizer from theano.gof.opt import (
from theano.gof.opt import copy_stack_trace LocalMetaOptimizerSkipAssertionError,
copy_stack_trace,
from theano.tensor.nnet.corr import CorrMM, CorrMM_gradInputs, CorrMM_gradWeights local_optimizer,
from theano.tensor.nnet.corr3d import (
Corr3dMM,
Corr3dMMGradInputs,
Corr3dMMGradWeights,
)
from theano.tensor.nnet.blocksparse import (
SparseBlockGemv,
SparseBlockOuter,
sparse_block_gemv_inplace,
sparse_block_outer_inplace,
) )
from theano.tensor.nnet.abstract_conv import ( from theano.tensor.nnet.abstract_conv import (
AbstractConv2d, AbstractConv2d,
AbstractConv2d_gradWeights,
AbstractConv2d_gradInputs, AbstractConv2d_gradInputs,
) AbstractConv2d_gradWeights,
from theano.tensor.nnet.abstract_conv import (
AbstractConv3d, AbstractConv3d,
AbstractConv3d_gradWeights,
AbstractConv3d_gradInputs, AbstractConv3d_gradInputs,
AbstractConv3d_gradWeights,
get_conv_output_shape,
)
from theano.tensor.nnet.blocksparse import (
SparseBlockGemv,
SparseBlockOuter,
sparse_block_gemv_inplace,
sparse_block_outer_inplace,
) )
from theano.tensor.nnet.abstract_conv import get_conv_output_shape
from theano.tensor.opt import register_specialize_device
from theano.tensor import TensorType
from theano.tensor import opt
# Cpu implementation # Cpu implementation
from theano.tensor.nnet.conv import conv2d, ConvOp from theano.tensor.nnet.conv import ConvOp, conv2d
from theano.tensor.nnet.corr import CorrMM, CorrMM_gradInputs, CorrMM_gradWeights
from theano.tensor.nnet.corr3d import Corr3dMM, Corr3dMMGradInputs, Corr3dMMGradWeights
from theano.tensor.opt import in2out, register_specialize_device
from theano.tensor.type import TensorType
@gof.local_optimizer([SparseBlockGemv], inplace=True) @gof.local_optimizer([SparseBlockGemv], inplace=True)
...@@ -591,7 +586,7 @@ def local_abstractconv_check(node): ...@@ -591,7 +586,7 @@ def local_abstractconv_check(node):
AbstractConv3d_gradInputs, AbstractConv3d_gradInputs,
), ),
): ):
raise gof.opt.LocalMetaOptimizerSkipAssertionError( raise LocalMetaOptimizerSkipAssertionError(
"%s Theano optimization failed: there is no implementation " "%s Theano optimization failed: there is no implementation "
"available supporting the requested options. Did you exclude " "available supporting the requested options. Did you exclude "
'both "conv_dnn" and "conv_gemm" from the optimizer? If on GPU, ' 'both "conv_dnn" and "conv_gemm" from the optimizer? If on GPU, '
...@@ -603,7 +598,7 @@ def local_abstractconv_check(node): ...@@ -603,7 +598,7 @@ def local_abstractconv_check(node):
optdb.register( optdb.register(
"AbstractConvCheck", "AbstractConvCheck",
opt.in2out(local_abstractconv_check, name="AbstractConvCheck"), in2out(local_abstractconv_check, name="AbstractConvCheck"),
48.7, 48.7,
"fast_compile", "fast_compile",
"fast_run", "fast_run",
......
...@@ -13,11 +13,13 @@ import numpy as np ...@@ -13,11 +13,13 @@ import numpy as np
import theano import theano
from theano import config, gof, printing, scalar from theano import config, gof, printing, scalar
from theano.gof.opt import copy_stack_trace
from theano.printing import pprint from theano.printing import pprint
from theano.tensor import basic as tensor from theano.tensor import basic as tensor
from theano.tensor import elemwise, opt, NotScalarConstantError from theano.tensor import elemwise, opt
from theano.tensor.basic import NotScalarConstantError
from theano.tensor.type import values_eq_approx_remove_inf from theano.tensor.type import values_eq_approx_remove_inf
from theano.gof.opt import copy_stack_trace
############ ############
# #
...@@ -155,9 +157,10 @@ class ScalarSigmoid(scalar.UnaryScalarOp): ...@@ -155,9 +157,10 @@ class ScalarSigmoid(scalar.UnaryScalarOp):
val_hard = hard_sigmoid(data).eval() val_hard = hard_sigmoid(data).eval()
val_ultra = ultra_fast_sigmoid(data).eval() val_ultra = ultra_fast_sigmoid(data).eval()
import matplotlib.pyplot as plt
import os import os
import matplotlib.pyplot as plt
fig = plt.figure() fig = plt.figure()
ax = fig.add_subplot(111) ax = fig.add_subplot(111)
ax.plot(data, val) # , 'o-') ax.plot(data, val) # , 'o-')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论