def _convert_roialign(builder, node, graph, err):
    """
    convert to CoreML CropResize and Pooling Layer:
    https://github.com/apple/coremltools/blob/655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492/mlmodel/format/NeuralNetwork.proto#L2239
    https://github.com/apple/coremltools/blob/655b3be5cc0d42c3c4fa49f0f0e4a93a26b3e492/mlmodel/format/NeuralNetwork.proto#L1702
    """
    target_height = node.attrs.get('output_height', 1)
    target_width = node.attrs.get('output_width', 1)
    mode = node.attrs.get('mode', 'AVERAGE').upper()
    sampling_ratio = node.attrs.get('sampling_ratio', 0)
    spatial_scale = node.attrs.get('sampling_scale', 1.0)
    if node.inputs[2] in graph.inputs:
        graph.inputs.remove(node.inputs[2])
    builder.add_expand_dims(name=node.name + '_expand_0', input_name=node.
        inputs[0], output_name=node.inputs[0] + '_expanded', axes=[0])
    node.inputs[0] += '_expanded'
    builder.add_expand_dims(name=node.name + '_expand_2', input_name=node.
        inputs[2], output_name=node.inputs[2] + '_expanded', axes=[1])
    node.inputs[2] += '_expanded'
    builder.add_concat_nd(name=node.name + '_concat_indices', input_names=[
        node.inputs[2], node.inputs[1]], output_name=node.inputs[1] +
        '_rois', axis=1)
    node.inputs[1] += '_rois'
    builder.add_expand_dims(name=node.name + '_expand_1', input_name=node.
        inputs[1], output_name=node.inputs[1] + '_expanded', axes=[1, 3, 4])
    node.inputs[1] += '_expanded'
    builder.add_crop_resize(name=node.name + '_crop_resize', input_names=[
        node.inputs[0], node.inputs[1]], output_name=node.outputs[0] +
        '_crop_resized', target_height=target_height * sampling_ratio,
        target_width=target_width * sampling_ratio, mode='ROI_ALIGN_MODE',
        box_indices_mode='CORNERS_WIDTH_FIRST', spatial_scale=spatial_scale)
    builder.add_squeeze(name=node.name + '_squeeze', input_name=node.
        outputs[0] + '_crop_resized', output_name=node.outputs[0] +
        '_crop_resized_squeezed', axes=[1])
    builder.add_pooling(name=node.name + '_pool', height=sampling_ratio,
        width=sampling_ratio, layer_type=mode, input_name=node.outputs[0] +
        '_crop_resized_squeezed', output_name=node.outputs[0],
        stride_height=sampling_ratio, stride_width=sampling_ratio,
        padding_type='VALID')
