Some questions about my model #666
Answered
by
fcakyon
Linaom1214
asked this question in
Q&A
-
In my model, there is always a fake target in the upper left of the image, and I tested this for all sequences Here is my code class IRDetectionModel(DetectionModel):
def load_model(self):
self.model = BaseEngine(self.model_path)
def perform_inference(self, image: np.ndarray, image_size: int = 256):
image = cv2.resize(image, (image_size, image_size))
image = np.transpose(image,(2,0,1))
image = image / 255.
image = np.array(image,order='C',dtype=np.float32)
image = np.ravel(image)
prediction_result = self.model.infer(image)
prediction_result = np.reshape(prediction_result,(-1,5))
prediction_result = np.expand_dims(prediction_result, 0)
self._original_predictions = prediction_result
def _create_object_prediction_list_from_original_predictions(self,
shift_amount_list: Optional[List[int]] = [[0, 0]],
full_shape_list: Optional[List[int]] = None):
original_predictions = self._original_predictions
shift_amount_list = fix_shift_amount_list(shift_amount_list)
full_shape_list = fix_full_shape_list(full_shape_list)
# handle all predictions
object_prediction_list_per_image = []
for image_ind, image_predictions in enumerate(original_predictions):
shift_amount = shift_amount_list[image_ind]
full_shape = None if full_shape_list is None else full_shape_list[image_ind]
object_prediction_list =[]
for predictions in image_predictions:
x1 = int(predictions[0]*256)
y1 = int(predictions[1]*256)
x2 = int(predictions[2]*256)
y2 = int(predictions[3]*256)
bbox = [x1, y1, x2, y2]
if bbox[0] > bbox[2] or bbox[1] > bbox[3] or bbox[0] < 0 or bbox[1] < 0 or bbox[2] <0 or bbox[3] < 0:
continue
if full_shape is not None and (
bbox[1] > full_shape[0] or
bbox[3] > full_shape[0] or
bbox[0] > full_shape[1] or
bbox[2] > full_shape[1]):
continue
score = predictions[4]
if score < 0.8:
continue
if (x2 - x1) > 10 or (y2 - y1) > 10:
continue
category_id = 0
category_name = 'target'
object_prediction = ObjectPrediction(
bbox = bbox,
score = score,
category_id = category_id,
category_name = category_name,
shift_amount = shift_amount,
full_shape = full_shape,
bool_mask=None)
object_prediction_list.append(object_prediction)
object_prediction_list_per_image.append(object_prediction_list)
self._object_prediction_list_per_image = object_prediction_list_per_image
def predict(img, model, sw, sh, ohr, owwr, img_size):
result = get_sliced_prediction(
img, model, slice_width=sw,
slice_height=sh,
overlap_height_ratio=ohr,
overlap_width_ratio=owwr,
image_size = img_size,
verbose= 0,
postprocess_match_threshold= 0.5,
perform_standard_pred= True
)
bboxes = []
scores = []
result_len = result.to_coco_annotations()
for pred in result_len:
bboxes.append(pred['bbox'])
scores.append(pred['score'])
return bboxes, scores
def plot(image, bboxes, scores):
for box, score in zip(bboxes, scores):
if score > 0.9:
x1 = int(box[0])
y1 = int(box[1])
x2 = int(box[2])
y2 = int(box[3])
cv2.rectangle(image, (x1, y1), (x1+x2, y1+ y2), (255,0,0), 2) is some wrong ? |
Beta Was this translation helpful? Give feedback.
Answered by
fcakyon
Mar 17, 2022
Replies: 2 comments
-
@Linaom1214 have you tried calling |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
fcakyon
-
thanks very much . Isolve my issue |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Linaom1214 have you tried calling
get_sliced_prediction
withperform_standard_pred=False
? Does the issue persist that way?