Esempio n. 1
0
def get_packed_output(interpreter, score_threshold, top_k, image_scale=1.0):

    boxes = common.output_tensor(interpreter, 0)
    class_ids = common.output_tensor(interpreter, 1)
    scores = common.output_tensor(interpreter, 2)
    count = int(common.output_tensor(interpreter, 3))

    top_k_scores_id = np.argpartition(np.array(scores), top_k)[-top_k:]
    top_k_scores = scores[top_k_scores_id]
    threshold_pass = top_k_scores_id[top_k_scores >= score_threshold]

    boxes, scores, class_ids = boxes[threshold_pass], scores[threshold_pass], class_ids[threshold_pass]

    return [boxes, scores, class_ids, count]
Esempio n. 2
0
def get_output(interpreter, score_threshold, top_k, image_scale=1.0):
    """Returns list of detected objects."""
    boxes = common.output_tensor(interpreter, 0)
    category_ids = common.output_tensor(interpreter, 1)
    scores = common.output_tensor(interpreter, 2)

    def make(i):
        ymin, xmin, ymax, xmax = boxes[i]
        return Object(id=int(category_ids[i]),
                      score=scores[i],
                      bbox=BBox(xmin=np.maximum(0.0, xmin),
                                ymin=np.maximum(0.0, ymin),
                                xmax=np.minimum(1.0, xmax),
                                ymax=np.minimum(1.0, ymax)))

    return [make(i) for i in range(top_k) if scores[i] >= score_threshold]
Esempio n. 3
0
    def get_output(self, interpreter, score_threshold, top_k, image_scale=1.0):
        boxes = common.output_tensor(interpreter, 0)
        class_ids = common.output_tensor(interpreter, 1)
        scores = common.output_tensor(interpreter, 2)
        count = int(common.output_tensor(interpreter, 3))

        def make(i):
            ymin, xmin, ymax, xmax = boxes[i]
            return Object(id=int(class_ids[i]),
                          score=scores[i],
                          bbox=BBox(xmin=np.maximum(0.0, xmin),
                                    ymin=np.maximum(0.0, ymin),
                                    xmax=np.minimum(1.0, xmax),
                                    ymax=np.minimum(1.0, ymax)))

        return [make(i) for i in range(top_k) if scores[i] >= score_threshold]
Esempio n. 4
0
def get_detection_output(interpreter):
    threshold = .6

    boxes = common.output_tensor(interpreter, 0)
    classes = common.output_tensor(interpreter, 1)
    scores = common.output_tensor(interpreter, 2)
    count = int(common.output_tensor(interpreter, 3))

    hand_detections = []
    for i in range(count):
        if scores[i] > threshold:
            hand_detections.append(boxes[i])
    #print(hand_detections)
    #sys.stdout.flush()

    return hand_detections
Esempio n. 5
0
def get_emotion(interpreter, top_k=1, score_threshold=0.1):
    scores = common.output_tensor(interpreter, 0)
    print(scores)
    categories = [
        Category(i, scores[i])
        for i in np.argpartition(scores, -top_k)[-top_k:]
        if scores[i] >= score_threshold
    ]
    return sorted(categories, key=operator.itemgetter(1), reverse=True)
def get_output(interpreter, top_k, score_threshold):
    """Returns no more than top_k categories with score >= score_threshold."""
    scores = common.output_tensor(interpreter, 0)
    categories = [
        Category(i, scores[i])
        for i in np.argpartition(scores, -top_k)[-top_k:]
        if scores[i] >= score_threshold
    ]
    return sorted(categories, key=operator.itemgetter(1), reverse=True)
Esempio n. 7
0
def get_output(interpreter, image_scale=1.0):
    """Returns list of detected objects."""
    boxes = common.output_tensor(interpreter, 0)
    class_ids = common.output_tensor(interpreter, 1)
    scores = common.output_tensor(interpreter, 2)
    count = int(common.output_tensor(interpreter, 3))

    def make(i):
        ymin, xmin, ymax, xmax = boxes[i]
        return Object(id=int(class_ids[i]),
                      score=scores[i],
                      bbox=BBox(xmin=np.maximum(0.0, xmin),
                                ymin=np.maximum(0.0, ymin),
                                xmax=np.minimum(1.0, xmax),
                                ymax=np.minimum(1.0, ymax)))

    return [make(i) for i in range(len(scores))
            if not np.isnan(class_ids[i])]  #if scores[i] >= score_threshold]
Esempio n. 8
0
def get_output_CAM(interpreter, dense_layer_weight, cam_w, cam_h):
    scaling = False
    CAM = common.output_tensor(interpreter,
                               0,
                               dense_layer_weight,
                               scaling=scaling)
    if scaling == True:
        pass
    else:
        CAM = cv2.resize(CAM, (cam_w, cam_h))  # 이거 한 번 하자고 cv2 부르니..?
        return CAM
Esempio n. 9
0
def create_pose(model, points):
    common.set_input_pose(model, points)
    model.invoke()
    scores = common.output_tensor(model, 0)

    x = points[:, 0::2]
    y = points[:, 1::2]
    z_pred = np.array(scores)
    z_pred = np.reshape(z_pred, (-1, len(scores)))

    pose = np.stack((x, y, z_pred), axis=-1)
    pose = np.reshape(pose, (len(points), -1))

    return pose
Esempio n. 10
0
def gen_frames():  # generate frame by frame from camera
    #Current regression model is unstable, so we take running averages of sin, cos, and angle to stabilize the values
    moving_window = 10
    runsin = np.zeros(moving_window)
    runcos = np.zeros(moving_window)
    runtheta = np.zeros(moving_window)

    while True:
        ret, frame = cap.read()
        if not ret:
            break
        cv2_im = frame

        cv2_im_rgb = cv2.cvtColor(cv2_im, cv2.COLOR_BGR2RGB)
        pil_im = Image.fromarray(cv2_im_rgb)

        common.set_input(interpreter, pil_im)
        interpreter.invoke()
        #Uncomment the following if you need to use bounding boxes or classification schemes and to use it for overlay

        #objs = get_output(interpreter, score_threshold=args.threshold, top_k=args.top_k)
        #cv2_im = append_objs_to_img(cv2_im, objs, labels)
        sincos = common.output_tensor(interpreter, 0)
        runsin = np.roll(runsin, 1)
        runsin[0] = sincos[0]
        runcos = np.roll(runcos, 1)
        runcos[0] = sincos[1]
        runtheta = np.roll(runtheta, 1)
        runtheta[0] = 180 / np.pi * np.arctan2(sincos[0], sincos[1])
        cv2_im = cv2.putText(cv2_im, 'angle: {}'.format(np.average(runtheta)),
                             (0, 480 - 90), cv2.FONT_HERSHEY_SIMPLEX, 1.0,
                             (255, 0, 0), 2)
        cv2_im = cv2.putText(cv2_im, 'sin: {}'.format(np.average(runsin)),
                             (0, 480 - 50), cv2.FONT_HERSHEY_SIMPLEX, 1.0,
                             (255, 0, 0), 2)
        cv2_im = cv2.putText(cv2_im, 'cos: {}'.format(np.average(runcos)),
                             (0, 480 - 10), cv2.FONT_HERSHEY_SIMPLEX, 1.0,
                             (255, 0, 0), 2)
        sd.putNumber(
            "WOF Angle",
            180 / np.pi * np.arctan2(np.average(runsin), np.average(runcos)))
        ret, buffer = cv2.imencode('.jpg', frame)
        frame = buffer.tobytes()
        yield (b'--frame\r\n'
               b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n'
               )  # concat frame one by one and show result

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
Esempio n. 11
0
def get_features(interpreter, patches):
    
    #patches je lista ndarray objekata, treba pretvoriti u tenzor istih dimenzija ili sliku po sliku ubacivat
    features = []
    for patch in patches:
        if 0 in patch.shape:
            features.append(None)
            continue

        common.set_input(interpreter, Image.fromarray(patch))
        interpreter.invoke()
        feature = common.output_tensor(interpreter, 0)
        features.append(feature)

    return features
Esempio n. 12
0
def get_classification_output(interpreter):
    scores = common.output_tensor(interpreter, 0)
    #print(scores)
    #sys.stdout.flush()
    return scores