sergiomsilva / alpr-unconstrained

License Plate Detection and Recognition in Unconstrained Scenarios
Other
1.71k stars 604 forks source link

Unable to load wpod model #145

Open bhargavravat opened 3 years ago

bhargavravat commented 3 years ago

ValueError: Tensor Tensor("concatenate_1/concat:0", shape=(?, ?, ?, 8), dtype=float32) is not an element of this graph.

I am trying to receive an image from using socket io and then trying to apply it to wpod net for number plate detection. But I am getting above mentioned error.

Here is the code snippet output_dir = 'lp_images/' lp_threshold = .5 wpod_net_path = 'data/lp-detector/wpod-net_update1.h5' wpod_net = load_model(wpod_net_path) ocr_threshold = .4 ocr_weights = 'data/ocr/ocr-net.weights' ocr_netcfg = 'data/ocr/ocr-net.cfg' ocr_dataset = 'data/ocr/ocr-net.data' ocr_net = dn.load_net(ocr_netcfg.encode(), ocr_weights.encode(), 0) ocr_meta = dn.load_meta(ocr_dataset.encode()) ` def anpr_detection(img_np, Rwidth , Rheight, sId , ske): print ("In Side anpr_detection ======>") frame = img_np w = frame.shape[0] h = frame.shape[1] ratio = float(max(frame.shape[:2]))/min(frame.shape[:2]) side = int(ratio*288.) bound_dim = min(side + (side%(2**4)),608) print ("bound_dim ==>",bound_dim) print (type(frame))

wpod_net = load_model(wpod_net_path)

Llp,LlpImgs,_ = detect_lp(wpod_net,im2single(frame),bound_dim,2**4,(240,80),lp_threshold)
if len(LlpImgs) > 0:
    print ("LlpImgs ========> ")
    Ilp = LlpImgs[0]
    s = Shape(Llp[0].pts)
    for shape in [s]:
        ptsarray = shape.pts.flatten()
        try: 
            frame = cv2.rectangle(frame,(int(ptsarray[0]*h), int(ptsarray[5]*w)),(int(ptsarray[1]*h),int(ptsarray[6]*w)),(0,255,0),3)
            X1 = int(ptsarray[0]*h)
            Y1 = int(ptsarray[5]*w)
            X2 = int(ptsarray[1]*h)
            Y2 = int(ptsarray[6]*w)
            Pwidth = X2 - X1
            Pheight = Y2 - Y1
        except:
            traceback.print_exc()
            sys.exit(1)
    cv2.imwrite('%s/_lp.png' % (output_dir),Ilp*255.)
    R,(width,height) = detect(ocr_net, ocr_meta, 'lp_images/_lp.png'.encode() ,thresh=ocr_threshold, nms=None)

    if len(R):
        L = dknet_label_conversion(R,width,height)
        L = nms(L,.45)
        L.sort(key=lambda x: x.tl()[0])
        lp_str = ''.join([chr(l.cl()) for l in L])
        print("License Plate Detected: ", lp_str)`
Harsha-1729 commented 3 years ago

Check if this helps you We need wpod-net.json file as well to load the model. I don't see any .json file being read in your code. I am able to load the wpod model successfully

image

TDiblik commented 1 year ago

Hi, I've encountered the same error. I was able to resolve it by simply re-downloading the models