frame

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

mvNCComplile caffe SSD_MobileNet example in ncappzoo, got "Exception: mvncStatus.ERROR"

I installed ncsdk1.12.00.01,and I can make run successfully in the fold "ncappzoo/caffe/SSD_MobileNet",every thing looks good.
then,I want to use usb cam,so I write the code as follw:

import numpy as np  
import sys,os  
import cv2
import time
import mvnc.mvncapi as mvnc
from utils import visualize_output
from utils import deserialize_output

CLASSES = ('background', 'aeroplane', 'bicycle', 'bird', 'boat',
                         'bottle', 'bus', 'car', 'cat', 'chair',
                         'cow', 'diningtable', 'dog', 'horse',
                         'motorbike', 'person', 'pottedplant',
                         'sheep', 'sofa', 'train', 'tvmonitor')
PATH_TO_CKPT = "graph2"
NUM_PREDICTIONS = 5

def preprocess(src):
    img = cv2.resize(src, (300,300))
    img = img - 127.5
    img = img * 0.007843
    img = img.astype(np.float16)
    return img

def ncs_prepare():
    print("[INFO] finding NCS devices...")
    mvnc.SetGlobalOption(mvnc.GlobalOption.LOG_LEVEL, 10)
    devices = mvnc.EnumerateDevices()   
    if len(devices) == 0:
            print("[INFO] No devices found. Please plug in a NCS")
            quit()

    print("[INFO] found {} devices. device0 will be used. "
          "opening device0...".format(len(devices)))
    device = mvnc.Device(devices[0])
    device.OpenDevice()   
    return device

def graph_prepare(device):
    print("[INFO] loading the graph file into RPi memory...")    
    with open(PATH_TO_CKPT, mode="rb") as f:
            graph_in_memory = f.read()    

    print("[INFO] allocating the graph on the NCS...")
    detection_graph = device.AllocateGraph(graph_in_memory)    
    return detection_graph

def predict(orgImage, graph):
    # preprocess the image
    image = preprocess(orgImage)

    # send the image to the NCS and run a forward pass to grab the
    # network predictions
    graph.LoadTensor(image, None)
    output, _ = graph.GetResult()
    output_dict = deserialize_output.ssd( output, 0.6, orgImage.shape )

    # grab the number of valid object predictions from the output,
    # then initialize the list of predictions
    print(output_dict)
    num_valid_boxes = output[0]
    predictions = []
    # loop over results
    if int(num_valid_boxes)!=0:
        for box_index in range(int(num_valid_boxes)):
            # calculate the base index into our array so we can extract
            # bounding box information
            base_index = 7 + box_index * 7

            # boxes with non-finite (inf, nan, etc) numbers must be ignored
            if (not np.isfinite(output[base_index]) or
                not np.isfinite(output[base_index + 1]) or
                not np.isfinite(output[base_index + 2]) or
                not np.isfinite(output[base_index + 3]) or
                not np.isfinite(output[base_index + 4]) or
                not np.isfinite(output[base_index + 5]) or
                not np.isfinite(output[base_index + 6])):
                continue

            # extract the image width and height and clip the boxes to the
            # image size in case network returns boxes outside of the image
            # boundaries
            (h, w) = image.shape[:2]
            x1 = max(0, int(output[base_index + 3] * w))
            y1 = max(0, int(output[base_index + 4] * h))
            x2 = min(w, int(output[base_index + 5] * w))
            y2 = min(h, int(output[base_index + 6] * h))

            # grab the prediction class label, confidence (i.e., probability),
            # and bounding box (x, y)-coordinates
            pred_class = int(output[base_index + 1])
            pred_conf = output[base_index + 2]
            pred_boxpts = ((x1, y1), (x2, y2))

            # create prediciton tuple and append the prediction to the
            # predictions list
            prediction = (pred_class, pred_conf, pred_boxpts)
            predictions.append(prediction)

            p1 = (pred_boxpts[0][0], pred_boxpts[0][1])
            p2 = (pred_boxpts[1][0], pred_boxpts[1][1])
            cv2.rectangle(orgImage, (x1, y1), (x2, y2), (0,255,0))
            p3 = (max(p1[0], 15), max(p1[1], 15))
            title = "%s:%.2f" % (CLASSES[int(pred_class)], pred_conf)
            cv2.putText(orgImage, title, p3, cv2.FONT_ITALIC, 0.6, (0, 255, 0), 1)
    cv2.imshow("SSD", orgImage)
    k = cv2.waitKey(1)

    return predictions

if __name__ == '__main__':
    device=ncs_prepare()
    graph=graph_prepare(device)

    camera = cv2.VideoCapture(0)
    while camera.isOpened():
        utc = time.time()
        ret, frame = camera.read()
        frame=frame[90:390,170:470]  

        predict(frame,graph)
        print(time.time()- utc)


    graph.DeallocateGraph()
    device.CloseDevice()
    pass

when use origial file "graph" every thing is ok.then I use mvNCCompile to transform MobileNetSSD_deploy.caffemodel and MobileNetSSD_deploy.prototxt which is originally in the fold "ncappzoo/caffe/SSD_MobileNet" to graph which names graph2.The command line is:
mvNCCompile MobileNetSSD_deploy.prototxt -w MobileNetSSD_deploy.caffemodel -s 21 -is 300 300 -o graph2

next,i change the code from PATH_TO_CKPT = "graph" to PATH_TO_CKPT = "graph2",the bad thing happened.
the code run a few second,then it got an exception:

============================log================================
Found stale device, resetting
[INFO] finding NCS devices...
Device 0 Address: 10 - VID/PID 03e7:2150
[INFO] found 1 devices. device0 will be used. opening device0...
Starting wait for connect with 2000ms timeout
Found Address: 10 - VID/PID 03e7:2150
Found EP 0x81 : max packet size is 512 bytes
Found EP 0x01 : max packet size is 512 bytes
Found and opened device
Performing bulk write of 865724 bytes...
Successfully sent 865724 bytes of data in 74.210579 ms (11.125351 MB/s)
Boot successful, device address 10
Found Address: 10 - VID/PID 03e7:f63b
[INFO] loading the graph file into RPi memory...
done
Booted 10 -> VSC
[INFO] allocating the graph on the NCS...

......

Traceback (most recent call last):
File "/home/zy/eclipse-workspace/caffe-ssd-ncsdk1/unoNCSTestCam.py", line 126, in
predict(frame,graph)
File "/home/zy/eclipse-workspace/caffe-ssd-ncsdk1/unoNCSTestCam.py", line 59, in predict
graph.LoadTensor(image, None)
File "/usr/local/lib/python3.5/dist-packages/mvnc/mvncapi.py", line 255, in LoadTensor
raise Exception(Status(status))
Exception: mvncStatus.ERROR
============================log================================

could you help me?

Comments

  • 6 Comments sorted by Votes Date Added
  • @firefox1200 Looks like your compile line may have a typo: mvNCCompile MobileNetSSD_deploy.prototxt -w MobileNetSSD_deploy.caffemodel -s 21 -is 300 300 -o graph2. Change the -s 21 to -s 12 then compile the graph file again and let me know if it works for you.

  • hi,Tome
    Thank you for your reply!
    I change the -s 21 to -s 12,the mvncStatus.ERROR disappear,the code can run now.But there is something wrong with it.it identifies so many things which do not exist.
    and I has a question,why Change the-s 21 to -s 12?
    There is a part of MobileNetSSD_deploy.prototxt:

      detection_output_param {
        num_classes: 21
        share_location: true
        background_label_id: 0
        nms_param {
          nms_threshold: 0.45
          top_k: 100
        }
        code_type: CENTER_SIZE
        keep_top_k: 100
        confidence_threshold: 0.25
      }
    }
    

    I think num_classes=21,so I put 21 for parameter "-s".Why 12!?
    I need your help!

  • @firefox1200
    The meaning of "-s" = Number of Neural Compute Stick Internal Shave Core

    There are twelve shave core inside the Neural Compute Stick.
    If you specify "-s 1", the performance will be one-twelfth.
    It has nothing to do with "num_classes" of SSD.

  • hi,PINTO
    Thank you very much.I realize I make a stupid mistake which almost make me give up movidius in my project.

    But I want report something to you and Tome_at_Intel.

    1.I think if I use more Shave Cores to compute, the computing speed will be faster,Why the default value of the parameter "-s" is set to 1,I think the default value of parameter "-s" should be max number of shaves in the device.And if user set a number more than max number of shaves,the mvNCCompile or API should give clear error info to user.

    2.How can I know max number of shaves in the device?

    3.It is a magic thing for me. Because of guessing all the bad things due to problems of ncsdk installation,I install ncsdk many times in fact. In one of my environments,I got a gragh using mvNCCompile with -s 21.Unexpectedly,my code can run with it.But the speed is less than 2 frame/sec.WHY?!

    At last,thank you very much again! And I hope my reports are useful to you.

  • edited October 14 Vote Up0Vote Down

    @firefox1200
    Please note that I am an informal comment because I am not an employee of Intel.

    Why the default value of the parameter "-s" is set to 1

    The concept of this product is to provide low power consumption and high performance with low performance edge device.
    If you use Shave Core a lot, the performance will rise, but the power consumption will increase accordingly.
    Based on the product concept, I think that it is effective that the default shaving core number is small.

    2.How can I know max number of shaves in the device?

    Show below.
    https://movidius.github.io/ncsdk/ncs.html
    And, @Tome_at_Intel 's comment.
    https://ncsforum.movidius.com/discussion/comment/2960/#Comment_2960

    my code can run with it.But the speed is less than 2 frame/sec.WHY?!

    I do not know what kind of code you are writing.
    Elements that affect performance,
    (1)Video input resolution・・・The smaller the smaller the better the performance will improve dramatically.
    (2)Efficient program・・・At least 20% ~ 30% performance may improve.
    (3)USB Camera performance・・・On my experience, It seems that USB cameras that support uncompressed data transfer by YUYV demonstrate high performance.

    For example, the following "program" achieves 6 FPS with one stick and 640x480 resolution. (-s 12)
    And, I achieved 30 FPS with a resolution of 320x240 and 5 sticks. (-s 12)
    https://github.com/PINTO0309/MobileNet-SSD-RealSense.git

  • @firefox1200 Thank you for the feedback. I agree that there needs to be a more informative error message when a user specifies more SHAVEs than a device currently has and we will work to make that change.

    Here are some links for docs on the NCS, NCSDK, and the mvNCCompile tool.
    NCS: https://movidius.github.io/ncsdk/ncs.html
    NCSDK: https://developer.movidius.com/docs.
    mvNCCompile: https://movidius.github.io/ncsdk/tools/compile.html.

    Echoing on what PINTO mentioned, the -s option is to specify the number of SHAVE vector processors to be used with the NCS device. The Intel Movidius Neural Compute Stick (NCS) houses the Myriad 2 Vision Processing Unit and has 12 SHAVEs in total.

    Setting the default SHAVEs to 1 is a very safe default number and we leave it up to the user to determine how many they would like to use. You can always visit our documentation site to learn more about our products. Thanks.

Sign In or Register to comment.