def region_converter(top_slice, bot_size, top_size, filter_width = (1,1), stride = (1,1), pad = (0,0)):
    '''
    Works for conv or pool
    
vector<int> ConvolutionLayer<Dtype>::JBY_region_of_influence(const vector<int>& slice) {
    +  CHECK_EQ(slice.size(), 4) << "slice must have length 4 (ii_start, ii_end, jj_start, jj_end)";
    +  // Crop region to output size
    +  vector<int> sl = vector<int>(slice);
    +  sl[0] = max(0, min(height_out_, slice[0]));
    +  sl[1] = max(0, min(height_out_, slice[1]));
    +  sl[2] = max(0, min(width_out_, slice[2]));
    +  sl[3] = max(0, min(width_out_, slice[3]));
    +  vector<int> roi;
    +  roi.resize(4);
    +  roi[0] = sl[0] * stride_h_ - pad_h_;
    +  roi[1] = (sl[1]-1) * stride_h_ + kernel_h_ - pad_h_;
    +  roi[2] = sl[2] * stride_w_ - pad_w_;
    +  roi[3] = (sl[3]-1) * stride_w_ + kernel_w_ - pad_w_;
    +  return roi;
    +}
    '''
    assert len(top_slice) == 4
    assert len(bot_size) == 2
    assert len(top_size) == 2
    assert len(filter_width) == 2
    assert len(stride) == 2
    assert len(pad) == 2

    # Crop top slice to allowable region
    top_slice = [ss for ss in top_slice]   # Copy list or array -> list

    top_slice[0] = max(0, min(top_size[0], top_slice[0]))
    top_slice[1] = max(0, min(top_size[0], top_slice[1]))
    top_slice[2] = max(0, min(top_size[1], top_slice[2]))
    top_slice[3] = max(0, min(top_size[1], top_slice[3]))

    bot_slice = [-123] * 4

    bot_slice[0] = top_slice[0] * stride[0] - pad[0];
    bot_slice[1] = (top_slice[1]-1) * stride[0] + filter_width[0] - pad[0];
    bot_slice[2] = top_slice[2] * stride[1] - pad[1];
    bot_slice[3] = (top_slice[3]-1) * stride[1] + filter_width[1] - pad[1];
    
    return bot_slice
dataset/ETHPy150Open yosinski/deep-visualization-toolbox/find_maxes/caffe_misc.py/region_converter/original