我有一个Keras网络,有两个输入:
在我的网络定义中,我需要从输入图像中提取边界框定义的图像补丁,但是我不知道该怎么做(或者我的尝试没有用)。这是我目前为实现此目的而进行的尝试,有人可以帮助我理解按Keras中其他张量的值对张量进行切片吗?
# get masked image and bounding box information as inputs
masked_img = Input(shape=self.input_shape)
mask_bounding_box = Input(shape=(4,))
# fill in the masked region and extract the fill-in region
filled_img = self.generator(masked_img)
fill_in = K.slice(filled_img, (int(mask_bounding_box[0]), int(mask_bounding_box[1])),
(int(mask_bounding_box[2]), int(mask_bounding_box[3])))
有人知道该怎么做吗?正确方向的任何提示都会对我有所帮助...
提前谢谢!
答案 0 :(得分:0)
这是本机numpy解决方案。
//my js code is below
onmousemove = function(e)
{
// console.log("mouse location:", e.clientX, e.clientY)
if(e.clientY>200&&e.clientY<340&&e.clientX>90&&e.clientX<500)
{
batLeft=e.clientX;
batTop=e.clientY
$("#bat").css("left",e.clientX);
$("#bat").css("top",e.clientY);
$("#score").text(score);
}
}
Keras.backend.slice()需要开始和偏移量,因此您可以这样做:
import numpy as np
a = np.arange(48).reshape(3,4,4)
a
array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11],
[12, 13, 14, 15]],
[[16, 17, 18, 19],
[20, 21, 22, 23],
[24, 25, 26, 27],
[28, 29, 30, 31]],
[[32, 33, 34, 35],
[36, 37, 38, 39],
[40, 41, 42, 43],
[44, 45, 46, 47]]])
box = (1,1,2,2) # slicing from (1,1) to (2,2)
b = a[:, box[0]:box[2]+1, box[1]:box[3]+1] # slicing on all channels
b
array([[[ 5, 6],
[ 9, 10]],
[[21, 22],
[25, 26]],
[[37, 38],
[41, 42]]])