v]c@srdZdddgZddlZddlZddlZddlZddlmZddlm Z m Z dd l m Z m Z mZdd l mZdd l mZdd l mZd dlmZmZmZd dlmZmZmZdefdYZdZdZdefdYZdefdYZ dZ!de fdYZ"e dZ#dS(s3Base container class for all neural network models.tBlockt HybridBlockt SymbolBlockiN(t OrderedDicti(t mx_real_tt MXNetError(tsymboltndarrayt initializer(tSymbol(tNDArray(tnamei(t Parametert ParameterDicttDeferredInitializationError(t_indentt_brief_print_listt HookHandlet _BlockScopecBsDeZdZejZdZedZdZ dZ RS(s%Scope for collecting child `Block` s.cCs(||_i|_d|_d|_dS(N(t_blockt_countertNonet _old_scopet _name_scope(tselftblock((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyt__init__+s   cCsRttjdd}|dkr|dkr|ttjjdsZtjtjj_ntjjjjd|d}n|dkrt |}nt |j |}||fS|dkr|j j|d}d||f}|d|j |R?t_regroupRB(RCRJtretRHtres((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRKps " cBs=eZdZdddZdZdZdZdZe dZ e dZ dZ e d Z dd Zd d Zd ZdZdeeeddZdeedZddZdZdZdZejdeedZedZdZdZdZ dZ!RS(s Base class for all neural network layers and models. Your models should subclass this class. :py:class:`Block` can be nested recursively in a tree structure. You can create and assign child :py:class:`Block` as regular attributes:: from mxnet.gluon import Block, nn from mxnet import ndarray as F class Model(Block): def __init__(self, **kwargs): super(Model, self).__init__(**kwargs) # use name_scope to give child Blocks appropriate names. with self.name_scope(): self.dense0 = nn.Dense(20) self.dense1 = nn.Dense(20) def forward(self, x): x = F.relu(self.dense0(x)) return F.relu(self.dense1(x)) model = Model() model.initialize(ctx=mx.cpu(0)) model(F.zeros((10, 10), ctx=mx.cpu(0))) Child :py:class:`Block` assigned this way will be registered and :py:meth:`collect_params` will collect their Parameters recursively. You can also manually register child blocks with :py:meth:`register_child`. Parameters ---------- prefix : str Prefix acts like a name space. All children blocks created in parent block's :py:meth:`name_scope` will have parent block's prefix in their name. Please refer to `naming tutorial `_ for more info on prefix and naming. params : ParameterDict or None :py:class:`ParameterDict` for sharing weights with the new :py:class:`Block`. For example, if you want ``dense1`` to share ``dense0``'s weights, you can do:: dense0 = nn.Dense(20) dense1 = nn.Dense(20, params=dense0.collect_params()) cCs|dk|_tj|||j\|_|_|jjdrU|jd n|j|_t||_t |_ i|_ t |_ t |_ dS(NtRi(R+RR*t_aliast_prefixt_paramstendswithR t_scopeRt _childrent _reg_paramst_forward_hookst_forward_pre_hooks(RR#R$((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRs'+   c Csd}djg|jjD]B\}}t|trdjd|dt|jd^q}|jd|jj d|S( Ns{name}( {modstr} )s s ({key}): {block}tkeyRiR tmodstr( tjoint__dict__titemsR7RtformatRt__repr__t __class__R1(RtsRXRRY((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyR^s Xc Cst||rt||}t|ttfrt|t| rtdjd|dt|dt|qnt|tr|j||n:t|tr||j kst d||j |`_ for more info on prefix and naming. (RS(R((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyt name_scopes cCs|jS(skReturns this :py:class:`Block`'s parameter dictionary (does not include its children's parameters).(RQ(R((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyR$ scs|jt|jj}|s5|j|jn5tj||jfd|jjDx0|j j D]}|j|j d|qzW|S(sReturns a :py:class:`ParameterDict` containing this :py:class:`Block` and all of its children's Parameters(default), also can returns the select :py:class:`ParameterDict` which match some given regular expressions. For example, collect the specified parameters in ['conv1_weight', 'conv1_bias', 'fc_weight', 'fc_bias']:: model.collect_params('conv1_weight|conv1_bias|fc_weight|fc_bias') or collect all parameters whose names end with 'weight' or 'bias', this can be done using regular expressions:: model.collect_params('.*weight|.*bias') Parameters ---------- select : str regular expressions Returns ------- The selected :py:class:`ParameterDict` cs.i|]$\}}j|r||qS((tmatch(t.0R R(tpattern(s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pys /s tselect( RyR RQR#tupdateR$tretcompileR\RTRttcollect_params(RRRLtcld((R~s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRs &RNcsprd7nfd|jjD}x7|jjD]&\}}|j|j|qBW|S(NRqcs#i|]\}}||qS(((R}RXtval(R#(s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pys 7s (RUR\RTRt_collect_params_with_prefix(RR#RLR tchild((R#s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyR4s  cCs6|j}d|jD}tj||dS(sSave parameters to file. Saved parameters can only be loaded with `load_parameters`. Note that this method only saves parameters, not model structure. If you want to save model structures, please use :py:meth:`HybridBlock.export`. Parameters ---------- filename : str Path to file. References ---------- `Saving and Loading Gluon Models `_ cSs%i|]\}}|j|qS((t_reduce(R}RXR((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pys Ns N(RR\Rtsave(RtfilenameR$targ_dict((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pytsave_parameters<s cCsZtjdy |jj|d|jWn&tk rU}td|jnXdS(s[Deprecated] Please use save_parameters. Note that if you want load from SymbolBlock later, please use export instead. Save parameters to file. filename : str Path to file. ssave_params is deprecated. Please use save_parameters. Note that if you want load from SymbolBlock later, please use export instead. For details, see https://mxnet.incubator.apache.org/tutorials/gluon/save_load_params.htmlt strip_prefixsK%s save_params is deprecated. Using save_parameters may resolve this error.N(RvRwRRR#t ValueErrortmessage(RRte((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyt save_paramsQs  R'c CsUtj|}|j}| r-| r-dStd|jDs~~|jj|||||jd|d|dS|sxH|jD]7} | |kstd| |t|jfqWnx|D]w} | r| |krt d| |t|j jfn| |kr|| j || |d|d|qqWdS(sVLoad parameters from file previously saved by `save_parameters`. Parameters ---------- filename : str Path to parameter file. ctx : Context or list of Context, default cpu() Context(s) to initialize loaded parameters on. allow_missing : bool, default False Whether to silently skip loading parameters not represents in the file. ignore_extra : bool, default False Whether to silently ignore parameters from the file that are not present in this Block. cast_dtype : bool, default False Cast the data type of the NDArray loaded from the checkpoint to the dtype provided by the Parameter if any. dtype_source : str, default 'current' must be in {'current', 'saved'} Only valid if cast_dtype=True, specify the source of the dtype for casting the parameters References ---------- `Saving and Loading Gluon Models `_ Ncss|]}d|kVqdS(RqN((R}RH((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pys st cast_dtypet dtype_sources{Parameter '%s' is missing in file '%s', which contains parameters: %s. Set allow_missing=True to ignore missing parameters.sParameter '%s' loaded from file '%s' is not present in ParameterDict, which contains parameters %s. Set ignore_extra=True to ignore. ( RtloadRtanytkeysRR#R=RRRQt _load_init( RRtctxt allow_missingt ignore_extraRRtloadedR$R ((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pytload_parameterses,   & % cCs'tjd|j||||dS(s[Deprecated] Please use load_parameters. Load parameters from file. filename : str Path to parameter file. ctx : Context or list of Context, default cpu() Context(s) to initialize loaded parameters on. allow_missing : bool, default False Whether to silently skip loading parameters not represents in the file. ignore_extra : bool, default False Whether to silently ignore parameters from the file that are not present in this Block. s6load_params is deprecated. Please use load_parameters.N(RvRwR(RRRRR((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyt load_paramss cCs5|dkr$tt|j}n||j|R9RT(RRR ((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRds cCs t}|j|j||S(sRegisters a forward pre-hook on the block. The hook function is called immediately before :func:`forward`. It should not modify the input or output. Parameters ---------- hook : callable The forward hook function of form `hook(block, input) -> None`. Returns ------- :class:`mxnet.gluon.utils.HookHandle` (RtattachRW(Rthookthandle((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pytregister_forward_pre_hooks cCs t}|j|j||S(sRegisters a forward hook on the block. The hook function is called immediately after :func:`forward`. It should not modify the input or output. Parameters ---------- hook : callable The forward hook function of form `hook(block, input, output) -> None`. Returns ------- :class:`mxnet.gluon.utils.HookHandle` (RRRV(RRR((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pytregister_forward_hooks cCs5x$|jjD]}|j|qW|||S(sApplies ``fn`` recursively to every child block as well as self. Parameters ---------- fn : callable Function to be applied to each submodule, of form `fn(block)`. Returns ------- this block (RTRttapply(RtfnR((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRs  cCs |jj||||dS(sInitializes :py:class:`Parameter` s of this :py:class:`Block` and its children. Equivalent to ``block.collect_params().initialize(...)`` Parameters ---------- init : Initializer Global default Initializer to be used when :py:meth:`Parameter.init` is ``None``. Otherwise, :py:meth:`Parameter.init` takes precedence. ctx : Context or list of Context Keeps a copy of Parameters on one or many context(s). verbose : bool, default False Whether to verbosely print out details on initialization. force_reinit : bool, default False Whether to force re-initialization if parameter is already initialized. N(Rt initialize(RtinitRtverboset force_reinit((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRscKs.x'|jjD]}|j||qWdS(sMActivates or deactivates :py:class:`HybridBlock` s recursively. Has no effect on non-hybrid children. Parameters ---------- active : bool, default True Whether to turn hybrid on or off. static_alloc : bool, default False Statically allocate memory to improve speed. Memory usage may increase. static_shape : bool, default False Optimize for invariant input shapes between iterations. Must also set static_alloc to True. Change of input shapes is still allowed but slower. N(RTRtt hybridize(RtactivetkwargsR((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRscCsXx$|jjD]}|j|qWx*|jjD]\}}|j|q7WdS(sCast this Block to use another data type. Parameters ---------- dtype : str or numpy.dtype The new data type. N(RTRttcastR$R\(RtdtypeRRtparam((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRscGsdx$|jjD]}|||qW|j|}x'|jjD]}||||qFW|S(s1Calls forward. Only accepts positional arguments.(RWRttforwardRV(RRCRtout((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyt__call__s cGs tdS(sOverrides to implement forward computation using :py:class:`NDArray`. Only accepts positional arguments. Parameters ---------- *args : list of NDArray Input tensors. N(tNotImplementedError(RRC((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyR+s c sttgdfd}td<|ddtreplace(RCt flat_argsRGtxtflat_arg_shapestshapest shape_str((RRs2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyt_get_shape_strFs  1 cst|t s2|j s2tdj|jfd}ddlm}m}t|||fsj |j |ndS(Ns-"{}" must not be hybridized to print summary.cs|jj}td}d||df}t|<||d20} {:>42} {:>15}t-iPs Layer (type)s Output ShapesParam #t=s;Parameters in forward computation graph, duplicate includeds Total params: s Trainable params: s Non-trainable params: s,Shared params in forward computation graph: sUnique parameters in model: N(RRsRR]R>tdetach( RtinputsRt line_formatt total_paramsttrainable_paramst shared_paramstlayerth((RRRRs2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyR7sJ   !          N("R1R2R3RRR^RfRyROtpropertyR#R R{R$RRRRRiRRRdRRRRtUniformRRhRRRRR(((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRs:-      $   6        cBseZdZdddZdZdZdZdZdZ dZ ddZ e d Z d Zd Zd Zd Zde dZdZdZRS(s`HybridBlock` supports forwarding with both Symbol and NDArray. `HybridBlock` is similar to `Block`, with a few differences:: import mxnet as mx from mxnet.gluon import HybridBlock, nn class Model(HybridBlock): def __init__(self, **kwargs): super(Model, self).__init__(**kwargs) # use name_scope to give child Blocks appropriate names. with self.name_scope(): self.dense0 = nn.Dense(20) self.dense1 = nn.Dense(20) def hybrid_forward(self, F, x): x = F.relu(self.dense0(x)) return F.relu(self.dense1(x)) model = Model() model.initialize(ctx=mx.cpu(0)) model.hybridize() model(mx.nd.zeros((10, 10), ctx=mx.cpu(0))) Forward computation in :py:class:`HybridBlock` must be static to work with :py:class:`Symbol` s, i.e. you cannot call :py:meth:`NDArray.asnumpy`, :py:attr:`NDArray.shape`, :py:attr:`NDArray.dtype`, `NDArray` indexing (`x[i]`) etc on tensors. Also, you cannot use branching or loop logic that bases on non-constant expressions like random numbers or intermediate results, since they change the graph structure for each iteration. Before activating with :py:meth:`hybridize()`, :py:class:`HybridBlock` works just like normal :py:class:`Block`. After activation, :py:class:`HybridBlock` will create a symbolic graph representing the forward computation and cache it. On subsequent forwards, the cached graph will be used instead of :py:meth:`hybrid_forward`. Please see references for detailed tutorial. References ---------- `Hybrid - Faster training and easy deployment `_ cCsYtt|jd|d|d|_d|_d|_d|_t|_ g|_ dS(NR#R$(( ReRRt _cached_graphRt _cached_opt _out_formatt _in_formatRiRt_flags(RR#R$((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRs     cCs9tt|j||t|tr5|jndS(sRegisters parameters.N(ReRRfR7t_clear_cached_op(RR R((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRfscGs |jst|d\}|_t|dkrhgtt|D]}tjd|^qF}ntjdg}t||jd}d|jj D}|j |j t||}WdQXt|d\}|_ |tj |f|_n|jS(Ntinputisdata%dRkicSs%i|]\}}|j|qS((tvar(R}RHtj((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pys s toutput(RR@RR9trangeRRRKRUR\R{thybrid_forwardRtGroup(RRCRHRtgrouped_inputsR$R((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyt _get_graphs 5 cGsl|j|\}}dt|D}|j}|j}t|j}t|}x6|D].} | |ksh| |kshtd| qhWg|D]} | |kr| ^q} t| t|kr/djg|j D]"\} } | |krd| ^q} t j d| ddng|D]} | |kr6| ^q6} t| t|krdjt |t| } t j d| ddng}g}g|_ xwt|D]i\} } | |kr |j| |j jt|| fq|j| |j jt|| fqWd |fd |fg|j}tj|||_dS( NcSs"i|]\}}||jqS((R (R}RHRk((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pys s s Unknown input to HybridBlock: %ss, s%d-thsMThe %s input to HybridBlock is not used by any computation. Is this intended?Rris>Parameter %s is not used by any computation. Is this intended?t data_indicest param_indices(Rt enumerateRt list_inputsRsRR=R9RZR\RvRwR;t_cached_op_argsRBRhRiRRtCachedOpR(RRCRkRt data_namesR$t input_namest param_namestexpected_namesR RHtused_data_namestunusedtused_param_namesRRtflags((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyt _build_caches@    % %      cGsFy|j|Wn.tk rA}dj|}t|nXdS(NsCDeferred initialization failed because shape cannot be inferred. {}(t infer_shapet ExceptionR]R(RRCRt error_msg((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyt_deferred_infer_shapes  cGsA|jdkr|j|nt|d\}}||jksOtdy<g|jD](\}}|rx||n |j^q\}Wnutk r|j |g}xR|jD]C\}}|r|j ||q|j |j |jqWnX|j|}t |t r-|g}nt||jdS(NRsInvalid input formati(RRRR@RR=RRkRRRBt_finish_deferred_initR7R RKR(RRCRJtis_argRHtcargsR((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyt_call_cached_op#s&9    cCsd|_d|_dS(N((RRR(R((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyR:s cCsat|ts:tdt|tt|fntt|j|||jdS(NsChildren of HybridBlock must also be HybridBlock, but %s has type %s. If you are using Sequential, please try HybridSequential instead.(R7RRR>R?ReRdR(RRR ((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRd>s %cKsm||_t|j|_|j|r7|js@|jrPtjdnt t |j ||dS(Ns"{}" is being hybridized while still having forward hook/pre-hook. If "{}" is a child of HybridBlock, the hooks will not take effect.( RR;R\RRRVRWRvRwReRR(RRR((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRHs   cCs$|jtt|j|dS(N(RReRR(RR((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRQs c s|j|\}}t|d\}}tjdt`}t||fdt||D\}}} |dkrt|dj nWdQXdt|j |D} | j dt|j | Dx1|j jD]} t| | | jqWdS(sGeneric infer attributes.Rtrecordcs+i|]!\}}t||jqS((RR (R}RHR(tattr(s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pys [s iNcSsi|]\}}||qS(((R}RHR((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pys ^s cSsi|]\}}||qS(((R}R R((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pys _s (RR@Rvtcatch_warningsRhRtzipRRRtlist_argumentsRtlist_auxiliary_statesRRttsetattrR ( Rtinfer_fnRRCRRRtwt arg_attrst aux_attrstsdictRH((Rs2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyt _infer_attrsUs +  cGs|jdd|dS(s'Infers shape of Parameters from inputs.RRN(R(RRC((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRdscGs|jdd|dS(s+Infers data type of Parameters from inputs.t infer_typeRN(R(RRC((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRhsic Cs|jstdn|jd}|jd|d|t|j}t|j}i}xi|jjD]U\}} ||kr| j|d|s cs(i|]\}}|j|qS((Rk(R}RHR(R(s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pys s NsZHybridBlock requires the first argument to forward be either Symbol or NDArray, but got %scSs%i|]\}}|j|qS((R(R}RHR((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pys s (R7R tcontextRRRUR\RRR$RRRR R=R?R{R(RRRCR$RRH((Rs2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRs$  # # cOs tdS(sOverrides to construct symbolic graph for this `Block`. Parameters ---------- x : Symbol or NDArray The first input tensor. *args : list of Symbol or list of NDArray Additional input tensors. N(R(RtFRRCR((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRs N(R1R2R3RRRfRRRRRRdRhRRRRRRRR(((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRs"+   '       ! cCs|s dS|d}xg|D]_}d}xF|t|kro|t|kro||||kro|d7}q*W|| }qW|S(s#Get the common prefix for all namesRNii(R9(tnamesR#R RH((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyt_common_prefixs  ;cBs\eZdZedddZdZddZdZdZ dZ dZ RS( siConstruct block from symbol. This is useful for using pre-trained models as feature extractors. For example, you may want to extract the output from fc2 layer in AlexNet. Parameters ---------- outputs : Symbol or list of Symbol The desired output for SymbolBlock. inputs : Symbol or list of Symbol The Variables in output's argument that should be used as inputs. params : ParameterDict Parameter dictionary for arguments and auxililary states of outputs that are not inputs. Examples -------- >>> # To extract the feature from fc1 and fc2 layers of AlexNet: >>> alexnet = gluon.model_zoo.vision.alexnet(pretrained=True, ctx=mx.cpu(), prefix='model_') >>> inputs = mx.sym.var('data') >>> out = alexnet(inputs) >>> internals = out.get_internals() >>> print(internals.list_outputs()) ['data', ..., 'model_dense0_relu_fwd_output', ..., 'model_dense1_relu_fwd_output', ...] >>> outputs = [internals['model_dense0_relu_fwd_output'], internals['model_dense1_relu_fwd_output']] >>> # Create SymbolBlock that shares parameters with alexnet >>> feat_model = gluon.SymbolBlock(outputs, inputs, params=alexnet.collect_params()) >>> x = mx.nd.random.normal(shape=(16, 3, 224, 224)) >>> print(feat_model(x)) cCstj|}t|tr*|g}n|dkrag|D]}tj|dt^q=}n"g|D]}tj|^qh}t||}|dk r|jj|d|dt ddn|S(sImport model previously saved by `HybridBlock.export` or `Module.save_checkpoint` as a SymbolBlock for use in Gluon. Parameters ---------- symbol_file : str Path to symbol file. input_names : list of str List of input variable names param_file : str, optional Path to parameter file. ctx : Context, default None The context to initialize SymbolBlock on. Returns ------- SymbolBlock SymbolBlock loaded from symbol and parameter files. Examples -------- >>> net1 = gluon.model_zoo.vision.resnet18_v1( ... prefix='resnet', pretrained=True) >>> net1.hybridize() >>> x = mx.nd.random.normal(shape=(1, 3, 32, 32)) >>> out1 = net1(x) >>> net1.export('net1', epoch=1) >>> >>> net2 = gluon.SymbolBlock.imports( ... 'net1-symbol.json', ['data'], 'net1-0001.params') >>> out2 = net2(x) RRRRtsavedN( RRR7R>RRRRRRh(t symbol_fileRt param_fileRRRHRRL((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pytimportss"  +" (c Cssd}djdjd|jddt|jddt|jdjg}|jd |jjd |S( Ns{name}( {modstr} )s s%{block} : {numinputs} -> {numoutputs}Rit numinputsit numoutputsR RY(RZR]RR9R:R_R1(RR`RY((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyR^s "c stt|jddddd|_td||_t|tj rpt |j dkrp|g}nt|t t frt |dkr|d}nt|d\}|_t|d\}|_tj|}t}xR|D]J}t |jj dks-tdt||j|jqWtjjd }xS|D]K}xB|jD]4} | jd t|ksktd | jqkWqXW|j} |j} t||| | \} } xIt| D];\}}||kr|jj |d t!d | |qqWxOt| D]A\}}||kr3|jj |ddd t!d | |q3q3W||f|_"t t#t |jj$fd|jj%D|_&dS(NR#R$RNiiRRs@Input symbols must be variable, but %s is an output of operatorst row_sparset__storage_type__sTSymbolBlock doesn't support Parameter '%s' because its storage type is 'row_sparse'.tallow_deferred_initRRRcs#i|]\}}||qS(((R}RXR(t len_prefix(s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pys Es ('ReRRRRPR RQR7RR R9R:R;R<R@RRRRst get_internalsR=R>RR Rt_STORAGE_TYPE_STR_TO_IDRR R t_infer_param_typesRR$R"RhRR RR\RU(RRRR$tsymsRRRHtrow_sparse_storageRt arg_paramst aux_paramst arg_typest aux_typesRItaux((R*s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRsB * '   !    ' -!cGst|tr2|j|j||SWdQXnt|tsWtdt|t|gt|d\}}||j kstdt j |j d}|j dt |j d|Dtt||jdS(NsZHybridBlock requires the first argument to forward be either Symbol or NDArray, but got %sRsInvalid input formaticSs"i|]\}}||jqS((R (R}RxRm((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pys Rs i(R7R RRR R=R?R@R;RtcopyRt_composeR RKR(RRRCtin_fmtRL((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRGs "'cCs)|j}tt|j||_dS(N(RReRR(Rttmp((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRUs cCs$|jtt|j|dS(N(RReRR(RR((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRZs cOs tdS(N(R(RRRRCR((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyR^sN( R1R2R3R6RR$R^RRRRR(((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyRs/ .   cCsd}d}g|D]}|j^q}g} t} x\|D]T}|jd} | sjt| dkrtt} Pq;| j|jddq;W| rdt|| D} y|j| \}} }Wqtk rd\}}qXn|dkst|t|kr<g}x|D]} |j|q"Wn|dks`t|t|krg}x|D]} |j|qmWn||fS(sqUtility function that helps in inferring DType of args and auxs params from given input param. Parameters ---------- in_params: List of Symbol List of input symbol variables. out_params: Symbol Output symbol variable. arg_params: List of Str List of names of argument parametrs. aux_params: List of Str List of names of auxiliary parameters. default_dtype: numpy.dtype or str, default 'float32' Default data type for arg_params and aux_params, if unable to infer the type. Returns ------- arg_types: List of numpy.dtype List of arg_params type. Order is same as arg_params. Defaults to 'float32', if unable to infer type. aux_types: List of numpy.dtype List of aux_params type. Order is same as aux_params. Defaults to 'float32', if unable to infer type. iicSsi|]\}}||qS(((R}RxRm((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pys s N(NN( RR RhRR9RiRBR R(t in_paramst out_paramsR0R1t default_dtypeR2R3tin_paramtinput_sym_namestinput_sym_arg_typestcan_infer_input_typetinput_sym_arg_typeR$R((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyR-as4  $ $ ($R3t__all__R4R5RvRt collectionsRtbaseRRRNRRRR R R R t parameterR R RtutilsRRRtobjectRR@RKRRR RR-(((s2/tmp/pip-install-Qvdv_2/mxnet/mxnet/gluon/block.pyts0    5  )