Loading TOC...


   $operand as cntk:variable,
   $rois as cntk:variable,
   $pooling-type as xs:string,
   $roi-output-shape as cntk:shape,
   $spatial-scale as xs:double,
   $name as xs:string
) as cntk:function


The ROI-pooling operation computes a new matrix by selecting the maximum (max pooling) value in the pooling input for each region of interest (ROI). The regions of interest are given as the second input to the operator as the top left and bottom right corners of the regions in absolute pixels of the original image. The pooling input is computed per ROI by projecting the coordinates onto the input feature map (first input to the operator) and considering all overlapping positions. The projection uses the 'spatial scale' which is the size ratio of the input feature map over the input image size. The spatial scale can be computed by multiplying all strides that occur before the ROI-pooling and taking the inverse, e.g., a network that has four pooling layers with stride two would have a spatial scale of 1/16. The output shape's width and height are determined by the third argument, the output depth (number of filters) is the same as the input depth.

$operand The operand of the operation. a convolutional feature map as the input volume
$rois ROI coordinates as absolute pixel coordinates (x_min, y_min, x_max, y_max).
$roi-output-shape Dimensions (width, height) of the ROI output, as a BrainScript vector, e.g. (4:4).
$spatial-scale The scale of operand from the original image size. The default is 1/16, which matches for example AlexNet and VGG16 networks.
$name The name of the function instance in the network.


  xquery version "1.0-ml";

  let $input-variable := cntk:input-variable(cntk:shape((4,4,2)), "float")
  let $roi := cntk:input-variable(cntk:shape((4,4)), "float")
  let $model := cntk:ROI-pooling($input-variable, $roi, "Max", cntk:shape((2,2)), 1.0, "name")

  let $input-value := cntk:sequence(cntk:shape((4,4,2)),
    json:to-array(json:to-array((3, 5, 2, 6, 4, 2, 8, 3, 1, 6, 4, 7, 7, 3, 5, 9, 3, 5, 2, 6, 4, 2, 8, 3, 1, 6, 4, 7, 7, 3, 5, 9))),
    fn:true(), cntk:cpu(), "float")
  let $pair1 := json:to-array(($input-variable, $input-value))

  let $roi-value := cntk:sequence(cntk:shape((4,4)),
    json:to-array(json:to-array((1 to 16))),
    fn:true(), cntk:cpu(), "float")
  let $pair2 := json:to-array(($roi, $roi-value))

  let $input-pairs := json:to-array(($pair1, $pair2))
  let $output-variable := cntk:function-output($model)
  let $output-value := cntk:evaluate($model, $input-pairs, $output-variable, cntk:cpu())
  return (
  "Value Shape : ", xdmp:quote(cntk:value-shape($output-value)), "
  "Variable Owner : ", fn:replace(xdmp:quote(cntk:variable-owner($output-variable)), "Input\d*", "Input"), "
  "Result : ", cntk:value-to-array($output-variable, $output-value))

Stack Overflow iconStack Overflow: Get the most useful answers to questions from the MarkLogic community, or ask your own question.