如何基于max_pooling和avg_pooling操作min_pooling?

时间:2018-07-27 07:21:31

标签: python

我搜索库,然后在tensorflow API上,我们只有max_pooling(tf.nn.max_pool)和avg_pooling(tf.nn.avg_pool)操作,它们都在tensorflow / python / ops / nn_ops.py中定义。 我按照tensorflow / python / ops / nn_ops.py中的代码进行操作,并尝试更改代码以操作min_pooling,但由于未见任何数学运算(选择最大值或计算平均值)而未能成功。 ..)。您能告诉我代码在哪里,哪个函数可以帮助我们在代码内执行max_pooling和avg_pooling操作?

def _max_pool(input, ksize, strides, padding, data_format="NHWC", name=None):
  if not isinstance(ksize, (list, tuple)):
  raise TypeError(
    "Expected list for 'ksize' argument to "
    "'max_pool' Op, not %r." % ksize)
  ksize = [_execute.make_int(_i, "ksize") for _i in ksize]
  if not isinstance(strides, (list, tuple)):
    raise TypeError(
      "Expected list for 'strides' argument to "
      "'max_pool' Op, not %r." % strides)
  strides = [_execute.make_int(_i, "strides") for _i in strides]
  padding = _execute.make_str(padding, "padding")
  if data_format is None:
    data_format = "NHWC"
  data_format = _execute.make_str(data_format, "data_format")
  _ctx = _context.context()
  if _ctx.in_graph_mode():
    _, _, _op = _op_def_lib._apply_op_helper(
      "MaxPool", input=input, ksize=ksize, strides=strides, 
       padding=padding,
      data_format=data_format, name=name)
    _result = _op.outputs[:]
    _inputs_flat = _op.inputs
    _attrs = ("T", _op.get_attr("T"), "ksize", _op.get_attr("ksize"),
          "strides", _op.get_attr("strides"), "padding",
          _op.get_attr("padding"), "data_format",
          _op.get_attr("data_format"))
  else:
    _attr_T, (input,) = _execute.args_to_matching_eager([input], _ctx, 
                        _dtypes.float32)
    _attr_T = _attr_T.as_datatype_enum
    _inputs_flat = [input]
    _attrs = ("T", _attr_T, "ksize", ksize, "strides", strides, 
             "padding", padding, "data_format", data_format)
  _result = _execute.execute(b"MaxPool", 1, inputs=_inputs_flat,
                           attrs=_attrs, ctx=_ctx, name=name)
  _execute.record_gradient("MaxPool", _inputs_flat, _attrs, _result, 
                          name)
  _result, = _result
  return _result

在这段代码中,他们使用了一些函数,例如_op_def_lib._apply_op_helper,_execute.args_to_matching_eage,_execute.execute。。尽管如此,但我仍然看不到任何数学运算,因为我们知道该函数可以操作max_pooling和avg_pooling。非常感谢!

0 个答案:

没有答案