Git Product home page Git Product logo

Comments (1)

EMUNES avatar EMUNES commented on July 2, 2024

Another similiar problem occurs when I directly use images in size 512 for inference.
codes from baseline that I use:

detect_thresh = 0.3
nms_thresh = 0.5
size = 1024

nr = []
pos = []
for image_id, (test_image, emp_label) in enumerate(learn.data.test_ds):
    #mean, std = learn.data.stats

    pos.append([0, 0, 0, 0])
    nr.append(0)

    image_ori = test_image
    # ori_shape = image_ori.shape[:2]

    # image = cv2.resize(image_ori, (size, size))

    # image = pil2tensor(image / 255., np.float32).cuda()

    #image = transforms.Normalize(mean, std)(image)
    
    image = test_image.resize(1024).data.cuda()

    # class_pred_batch, bbox_pred_batch, _ = learn.model(image[None, :, :, :])
    
    class_pred_batch, bbox_pred_batch, _ = learn.model(image[None, :])

    for clas_pred, bbox_pred in zip(class_pred_batch, bbox_pred_batch):
        bbox_pred, scores, preds = process_output(clas_pred, bbox_pred, anchors, detect_thresh)

        if bbox_pred is not None:
            to_keep = nms(bbox_pred, scores, nms_thresh)
            bbox_pred, preds, scores = bbox_pred[to_keep].cpu(), preds[to_keep].cpu(), scores[to_keep].cpu()

            t_sz = torch.Tensor(ori_shape)[None].float()
            bbox_pred = rescale_box(bbox_pred, t_sz)

            temp_pos = [0, 0, 0, 0]
            for id, box in enumerate(bbox_pred[:2]):
                x = to_np(box[0] + box[2] / 2)
                y = to_np(box[1] + box[3] / 2)
                if id == 0:
                    temp_pos[ :2] = x,y
                    nr[image_id] = 1
                else:
                    temp_pos[2: ] = x, y
                    nr[image_id] = 2

output:

RuntimeError                              Traceback (most recent call last)
<ipython-input-65-883a98e5b6df> in <module>
     27 
     28     for clas_pred, bbox_pred in zip(class_pred_batch, bbox_pred_batch):
---> 29         bbox_pred, scores, preds = process_output(clas_pred, bbox_pred, anchors, detect_thresh)
     30 
     31         if bbox_pred is not None:

D:\ProgramFile\anaconda\envs\ai\lib\site-packages\object_detection_fastai\helper\object_detection_helper.py in process_output(clas_pred, bbox_pred, anchors, detect_thresh)
    227 
    228 def process_output(clas_pred, bbox_pred, anchors, detect_thresh=0.25):
--> 229     bbox_pred = activ_to_bbox(bbox_pred, anchors.to(clas_pred.device))
    230     clas_pred = torch.sigmoid(clas_pred)
    231 

D:\ProgramFile\anaconda\envs\ai\lib\site-packages\object_detection_fastai\helper\object_detection_helper.py in activ_to_bbox(acts, anchors, flatten)
     74     if flatten:
     75         acts.mul_(acts.new_tensor([[0.1, 0.1, 0.2, 0.2]]))
---> 76         centers = anchors[...,2:] * acts[...,:2] + anchors[...,:2]
     77         sizes = anchors[...,2:] * torch.exp(acts[...,2:])
     78         return torch.cat([centers, sizes], -1)

RuntimeError: The size of tensor a (24480) must match the size of tensor b (24192) at non-singleton dimension 0

Two numbers don't match, same as above - 24480 (the number of anchors) and 24192 (what is this about). I guess this has something to do with the resizing as both those problems occur after resizing but I really can't come up with anything to fix this.
Also I'm using GPU for training.

from objectdetection.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.