|
|
@ -19,9 +19,10 @@ from ..layer_helper import LayerHelper
|
|
|
|
from ..initializer import Normal, Constant
|
|
|
|
from ..initializer import Normal, Constant
|
|
|
|
from ..framework import Variable
|
|
|
|
from ..framework import Variable
|
|
|
|
from ..param_attr import ParamAttr
|
|
|
|
from ..param_attr import ParamAttr
|
|
|
|
from layer_function_generator import autodoc
|
|
|
|
from layer_function_generator import autodoc, templatedoc
|
|
|
|
from tensor import concat
|
|
|
|
from tensor import concat
|
|
|
|
import utils
|
|
|
|
import utils
|
|
|
|
|
|
|
|
import random
|
|
|
|
|
|
|
|
|
|
|
|
__all__ = [
|
|
|
|
__all__ = [
|
|
|
|
'fc',
|
|
|
|
'fc',
|
|
|
@ -801,7 +802,22 @@ def gru_unit(input,
|
|
|
|
return updated_hidden, reset_hidden_pre, gate
|
|
|
|
return updated_hidden, reset_hidden_pre, gate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@templatedoc()
|
|
|
|
def linear_chain_crf(input, label, param_attr=None):
|
|
|
|
def linear_chain_crf(input, label, param_attr=None):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
Linear Chain CRF.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
${comment}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
|
|
input(${emission_type}): ${emission_comment}
|
|
|
|
|
|
|
|
label(${label_type}): ${label_comment}
|
|
|
|
|
|
|
|
param_attr(ParamAttr): The attribute of the learnable parameter.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
${log_likelihood_comment}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
helper = LayerHelper('linear_chain_crf', **locals())
|
|
|
|
helper = LayerHelper('linear_chain_crf', **locals())
|
|
|
|
size = input.shape[1]
|
|
|
|
size = input.shape[1]
|
|
|
|
transition = helper.create_parameter(
|
|
|
|
transition = helper.create_parameter(
|
|
|
@ -827,7 +843,19 @@ def linear_chain_crf(input, label, param_attr=None):
|
|
|
|
return log_likelihood
|
|
|
|
return log_likelihood
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@templatedoc()
|
|
|
|
def crf_decoding(input, param_attr, label=None):
|
|
|
|
def crf_decoding(input, param_attr, label=None):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
${comment}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
|
|
input(${emission_type}): ${emission_comment}
|
|
|
|
|
|
|
|
param_attr(ParamAttr): The parameter attribute for training.
|
|
|
|
|
|
|
|
label(${label_type}): ${label_comment}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
${viterbi_path_comment}
|
|
|
|
|
|
|
|
"""
|
|
|
|
helper = LayerHelper('crf_decoding', **locals())
|
|
|
|
helper = LayerHelper('crf_decoding', **locals())
|
|
|
|
transition = helper.get_parameter(param_attr.name)
|
|
|
|
transition = helper.get_parameter(param_attr.name)
|
|
|
|
viterbi_path = helper.create_tmp_variable(dtype=helper.input_dtype())
|
|
|
|
viterbi_path = helper.create_tmp_variable(dtype=helper.input_dtype())
|
|
|
@ -4107,10 +4135,31 @@ def gather(input, index):
|
|
|
|
return out
|
|
|
|
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def random_crop(input, shape, seed=1):
|
|
|
|
@templatedoc()
|
|
|
|
|
|
|
|
def random_crop(x, shape, seed=None):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
${comment}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
>>> img = fluid.layers.data("img", [3, 256, 256])
|
|
|
|
|
|
|
|
>>> cropped_img = fluid.layers.random_crop(img, shape=[3, 224, 224])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
|
|
|
x(${x_type}): ${x_comment}
|
|
|
|
|
|
|
|
shape(${shape_type}): ${shape_comment}
|
|
|
|
|
|
|
|
seed(int|${seed_type}|None): ${seed_comment} By default, the seed will
|
|
|
|
|
|
|
|
get from `random.randint(-65536, 65535)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
${out_comment}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
helper = LayerHelper("random_crop", **locals())
|
|
|
|
helper = LayerHelper("random_crop", **locals())
|
|
|
|
dtype = helper.input_dtype()
|
|
|
|
dtype = helper.input_dtype()
|
|
|
|
out = helper.create_tmp_variable(dtype)
|
|
|
|
out = helper.create_tmp_variable(dtype)
|
|
|
|
|
|
|
|
if seed is None:
|
|
|
|
|
|
|
|
seed = random.randint(-65536, 65535)
|
|
|
|
|
|
|
|
|
|
|
|
if isinstance(seed, int):
|
|
|
|
if isinstance(seed, int):
|
|
|
|
seed_value = seed
|
|
|
|
seed_value = seed
|
|
|
|
seed = helper.create_tmp_variable(dtype="int64")
|
|
|
|
seed = helper.create_tmp_variable(dtype="int64")
|
|
|
|