-
Notifications
You must be signed in to change notification settings - Fork 4
Description
in my result,in detect function the bbox is already the coordinate of image include offset,so why need add offset again in to_coord function?
def to_coord(bbox, origin, space):
d = len(bbox.shape)
if d==1:
bbox = np.expand_dims(bbox,0)
space = space[::-1]
origin = origin[::-1]
center = (bbox[:,3:] + bbox[:,:3])/2*space + origin
center = center[:,::-1]
diam = l2norm((bbox[:,3:] - bbox[:,:3])*space)/3**0.5
coord = np.concatenate([center, diam],1)
if d==1:
coord = coord.flatten()
return coord
this is my code:
def detect(model, sample, batch_size=32):
candidates = []
for i, pixel_values in enumerate(torch.split(sample["pixel_values"].to(model.device), batch_size)):
img_shape = np.tile(np.array(pixel_values.shape[-3:]),2)
offsets = np.tile(sample["offsets"][i*batch_size:(i+1)*batch_size],2)
outputs = model(pixel_values=pixel_values)
bbox = outputs.bbox.cpu().numpy()*img_shape+offsets
coord = to_coord(bbox, sample["origin"], sample["space"])
logits = outputs.logits.cpu().numpy()
probabilities = sigmoid(logits)
candidates.append(np.concatenate([coord, probabilities], 1))
#candidates.append(np.concatenate([coord,logits],1))
candidates = np.concatenate(candidates,0)
#candidates = merge_cands(candidates)
# threshold cutoff
candidates = candidates[candidates[:,-1]>0.8]
return candidates
def to_coord(bbox, origin, space):
d = len(bbox.shape)
if d==1:
bbox = np.expand_dims(bbox,0)
space = space[::-1]
origin = origin[::-1]
center = (bbox[:,3:] + bbox[:,:3])/2
center = center[:,::-1]
diam = l2norm((bbox[:,3:] - bbox[:,:3])*space)/3**0.5
coord = np.concatenate([center, diam],1)
if d==1:
coord = coord.flatten()
return coord
def l2norm(x):
return np.sum(x**2,axis=-1,keepdims=True)**0.5
def sigmoid(x):
return 1 / (1 + np.exp(-x))