示例#1
0
def main():
    if not SERVER_URL:
        print('please specify server host:port')
        return

    video_fname = "/data/dataset/jackson-town-square.mp4"
    csv_in = "/data/dataset/jackson-town-square.csv"
    avg_fname = "/data/dataset/jackson-town-square.npy"
    num_frames = 500
    start_frame = 1

    data, nb_classes = dataPrep.get_data_for_test(
            csv_in, video_fname, avg_fname,
            num_frames=num_frames,
            start_frame=start_frame,
            OBJECTS=['car'],
            resol=(50, 50))

    X, Y = data
    print(Y)
    #r = requests.get(SERVER_URL + '/' + 'metadata')
    TP = 0
    TN = 0
    FP = 0
    FN = 0
    for i in range(len(X)):
        print("Sending request for %d frame" %(i))
        payload = {
                   'signature_name': 'serving_default',
                   'inputs': 
                      { 
                        'image': [ X[i].tolist() ]
                      },
                  }

        # print(payload) 
        r = requests.post(SERVER_URL + ':predict', json=payload)
        probs = r.json()['outputs']
        print('Confidence: %f'%(probs[0][1]))
        if probs[0][1] > 0.5:
            if Y[i][1] == 1.:
                TP +=1
            else:
                FP +=1
        else:
            if Y[i][1] == 0.:
                TN +=1
            else:
                FN +=1

    print('Accuracy: %f' % ((TP+TN)/float(TP+FP+TN+FN)))
示例#2
0
def main():
    SERVER_URL = 'http://localhost:8502/v1/models/spm'
    if not SERVER_URL:
        print('please specify server host:port')
        return

    video_fname = "/data/dataset/jackson-town-square.mp4"
    csv_in = "/data/dataset/jackson-town-square.csv"
    avg_fname = "/data/dataset/jackson-town-square.npy"
    num_frames = 500
    start_frame = 1

    data, nb_classes = dataPrep.get_data_for_test(
            csv_in, video_fname, avg_fname,
            num_frames=num_frames,
            start_frame=start_frame,
            OBJECTS=['car'],
            resol=(50, 50))

    X, Y = data

    '''   
    for i in range(len(X)):
        print("Sending request for %d frame" %(i))
        payload = {
                   'signature_name': 'serving_default',
                   'inputs': 
                      { 
                        'image': [ X[i].tolist() ]
                      },
                  }

        # print(payload) 
        r = requests.post(SERVER_URL + ':predict', json=payload)
        probs = r.json()['outputs']
        print('Confidence: %f'%(probs[0][1]))
    '''
    async def sendRequests(X,Y):
        pass
    loop = asyncio.get_event_loop()
    loop.run_until_complete(sendRequests(X,Y))
示例#3
0
def main():
    video_fname = "/data/dataset/jackson-town-square.mp4"
    csv_in = "/data/dataset/jackson-town-square.csv"
    avg_fname = "/data/dataset/jackson-town-square.npy"
    avg_fname_orig = "/data/dataset/jackson-town-square_400_600.npy"
    num_frames = 30
    start_frame = 3
    target = 'car'

    # Param: difference detector
    dist_metric = 'mse'
    thresh = 0.00024391713548410724  #0.002  #0.00024391713548410724
    frame_delay = 1
    feature_fn = RawImage.compute_feature
    get_distance_fn = RawImage.get_distance_fn

    # Param: specialized NN
    c_low = 0.10
    c_high = 0.90

    # Param: time
    ddTotalTime = 0
    sNNTotalTime = 0
    rNNTotalTime = 0

    start = time.time()
    data, nb_classes = dataPrep.get_data_for_test(csv_in,
                                                  video_fname,
                                                  avg_fname,
                                                  num_frames=num_frames,
                                                  start_frame=start_frame,
                                                  OBJECTS=[target],
                                                  resol=(50, 50),
                                                  shiftEn=1)
    X, Y = data
    print(X[0].shape)

    origData, orig_nb_classes = dataPrep.get_data_for_test(
        csv_in,
        video_fname,
        avg_fname_orig,
        num_frames=num_frames,
        start_frame=start_frame,
        OBJECTS=[target],
        resol=(400, 600),
        shiftEn=0)
    origX, origY = origData
    print(origX[0].shape)

    #    start = time.time()
    ddTotalTime = ddTotalTime + (time.time() - start)

    conf = None
    ddCount = 0
    sNNFrameCount = 0
    rNNFrameCount = 0

    for i in range(1):
        if i == 0:
            sNNFrameCount, rNNFrameCount, sNNTotalTime, rNNTotalTime, conf = runNNRequest(
                sNNFrameCount, rNNFrameCount, sNNTotalTime, rNNTotalTime, X[i],
                origX[i], c_low, c_high, target)

        print('Frame %d: Confidence = %f' % (i, conf))

    print("0. Total frames: {} from frame {} to frame {}".format(
        len(X), start_frame, start_frame + num_frames - 1))
    print("1. Difference detector: {} times, {:.2f} sec".format(
        ddCount, ddTotalTime))
    print("2. Specialized NN: {} times, {:.2f} sec".format(
        sNNFrameCount, sNNTotalTime))
    print("3. Reference NN: {} times, {:.2f} sec".format(
        rNNFrameCount, rNNTotalTime))
def main():
    if not SERVER_URL:
        print('please specify server host:port')
        return

    video_fname = "/data/dataset/jackson-town-square.mp4"
    csv_in = "/data/dataset/jackson-town-square.csv"
    avg_fname = "/data/dataset/jackson-town-square.npy"
    num_frames = 500
    start_frame = 1

    # Param: difference detector
    dist_metric = 'mse'
    thresh = 0.002  #0.00024391713548410724
    frame_delay = 1
    feature_fn = RawImage.compute_feature
    get_distance_fn = RawImage.get_distance_fn

    data, nb_classes = dataPrep.get_data_for_test(csv_in,
                                                  video_fname,
                                                  avg_fname,
                                                  num_frames=num_frames,
                                                  start_frame=start_frame,
                                                  OBJECTS=['car'],
                                                  resol=(50, 50))

    X, Y = data

    #r = requests.get(SERVER_URL + '/' + 'metadata')
    TP = 0
    TN = 0
    FP = 0
    FN = 0
    r = None
    posCount = 0
    for i in range(len(X)):
        print("Sending request for %d frame" % (i))
        payload = {
            'signature_name': 'serving_default',
            'inputs': {
                'image': [X[i].tolist()]
            },
        }

        # print(payload)
        if i == 0:
            r = requests.post(SERVER_URL + ':predict', json=payload)
        else:  # Difference detector start working from the 2nd frame
            features = get_features(feature_fn, X[i - 1:i + 1])
            dists = get_distances(get_distance_fn(dist_metric), features,
                                  frame_delay)
            if dists > thresh:
                posCount = posCount + 1
                r = requests.post(SERVER_URL + ':predict', json=payload)

        probs = r.json()['outputs']
        print('Confidence: %f' % (probs[0][1]))
        if probs[0][1] > 0.5:
            if Y[i][1] == 1.:
                TP += 1
            else:
                FP += 1
        else:
            if Y[i][1] == 0.:
                TN += 1
            else:
                FN += 1

    print("posCount = {}".format(posCount))
    print('Accuracy: %f' % ((TP + TN) / float(TP + FP + TN + FN)))
示例#5
0
def main(num_of_frames=50, num_of_workers=4):
    video_fname = "/data/dataset/jackson-town-square.mp4"
    csv_in = "/data/dataset/jackson-town-square.csv"
    avg_fname = "/data/dataset/jackson-town-square.npy"
    avg_fname_orig = "/data/dataset/jackson-town-square_400_600.npy"
    num_frames = num_of_frames
    start_frame = 5001
    target = 'car'

    # Param: difference detector
    dist_metric = 'mse'
    thresh = 0.00024391713548410724
    frame_delay = 1
    feature_fn = RawImage.compute_feature
    get_distance_fn = RawImage.get_distance_fn

    # Param: specialized NN
    c_low = 0.1
    c_high = 0.9

    #    start = time.time()

    data, nb_classes = dataPrep.get_data_for_test(csv_in,
                                                  video_fname,
                                                  avg_fname,
                                                  num_frames=num_frames,
                                                  start_frame=start_frame,
                                                  OBJECTS=[target],
                                                  resol=(50, 50),
                                                  shiftEn=1)
    X, Y = data

    origData, orig_nb_classes = dataPrep.get_data_for_test(
        csv_in,
        video_fname,
        avg_fname_orig,
        num_frames=num_frames,
        start_frame=start_frame,
        OBJECTS=[target],
        resol=(608, 608),
        shiftEn=0)
    origX, origY = origData

    meta_f = open('yolo.meta', 'r')
    metadata = json.loads(meta_f.read())

    # Run Difference Detector, and generate index of frames which need Specialized NN

    start = time.time()

    todos = [0]
    for i in range(1, len(X)):
        features = get_features(feature_fn, X[i - 1:i + 1])
        dists = get_distances(get_distance_fn(dist_metric), features,
                              frame_delay)
        if dists > thresh:
            todos.append(i)

    X_new = X[todos]
    origX_new = origX[todos]
    ''' 
    tasks = []
    for i in range(len(X_new)):
        task = asyncio.ensure_future(sendNNRequest(metadata, X_new[i:i+1], origX_new[i:i+1], c_low, c_high, target))
        tasks.append(task)
 
    loop = asyncio.get_event_loop()
    responses = loop.run_until_complete(asyncio.gather(*tasks)) 
    '''
    '''
    executor = concurrent.futures.ThreadPoolExecutor(
        max_workers=10,
    )
    '''
    executor = concurrent.futures.ProcessPoolExecutor(
        max_workers=num_of_workers, )

    loop = asyncio.get_event_loop()
    loop.run_until_complete(
        sendAllRequests(executor, metadata, X_new, origX_new, c_low, c_high,
                        target))

    print('Num of RNN: ', str(num_of_RNN), " Run Time: ", time.time() - start)
示例#6
0
def main():
    video_fname = "/data/dataset/jackson-town-square.mp4"
    csv_in = "/data/dataset/jackson-town-square.csv"
    avg_fname = "/data/dataset/jackson-town-square.npy"
    avg_fname_orig = "/data/dataset/jackson-town-square_400_600.npy"
    num_frames = 500
    start_frame = 5001
    target = 'car'
    
    # Param: difference detector
    dist_metric = 'mse'
    thresh = 0.00024391713548410724 #0.002  #0.00024391713548410724
    frame_delay = 1 
    feature_fn = RawImage.compute_feature
    get_distance_fn = RawImage.get_distance_fn

    # Param: specialized NN
    c_low = 0.10
    c_high = 0.90

    # Param: time
    ddTotalTime = 0
    sNNTotalTime = 0
    rNNTotalTime = 0

    start = time.time()        
    data, nb_classes = dataPrep.get_data_for_test(
            csv_in, video_fname, avg_fname,
            num_frames=num_frames,
            start_frame=start_frame,
            OBJECTS=[target],
            resol=(50, 50), shiftEn=1)
    X, Y = data
    print(X[0].shape)

    origData, orig_nb_classes = dataPrep.get_data_for_test(
            csv_in, video_fname, avg_fname_orig,
            num_frames=num_frames,
            start_frame=start_frame,
            OBJECTS=[target],
            resol=(400, 600), shiftEn=0)
    origX, origY = origData
    print(origX[0].shape)
    ddTotalTime = ddTotalTime + (time.time() - start)

    TP = 0
    TN = 0
    FP = 0
    FN = 0
    conf = None
    ddCount = 0
    sNNFrameCount = 0
    rNNFrameCount = 0
    for i in range(len(X)):
        if i == 0:
            sNNFrameCount, rNNFrameCount, sNNTotalTime, rNNTotalTime, conf = runNNRequest(
                sNNFrameCount, rNNFrameCount, sNNTotalTime, rNNTotalTime, X[i], origX[i], c_low, c_high, target)
        else: # Difference detector start working from the 2nd frame
            start = time.time()
            ddCount = ddCount + 1
            features = get_features(feature_fn, X[i-1:i+1])
            dists = get_distances(get_distance_fn(dist_metric), features, frame_delay)
            ddTotalTime = ddTotalTime + (time.time() - start)
            if dists > thresh:
                sNNFrameCount, rNNFrameCount, sNNTotalTime, rNNTotalTime, conf = runNNRequest(
                    sNNFrameCount, rNNFrameCount, sNNTotalTime, rNNTotalTime, X[i], origX[i], c_low, c_high, target)

        print('Frame %d: Confidence = %f'%(i, conf))
        if conf > 0.5:
            if Y[i][1] == 1.:
                TP +=1
            else:
                FP +=1
        else:
            if Y[i][1] == 0.:
                TN +=1
            else:
                FN +=1

    print("0. Total frames: {} from frame {} to frame {}".format(len(X), start_frame, start_frame+num_frames-1))
    print("1. Difference detector: {} times, {:.2f} sec".format(ddCount, ddTotalTime))
    print("2. Specialized NN: {} times, {:.2f} sec".format(sNNFrameCount, sNNTotalTime))
    print("3. Reference NN: {} times, {:.2f} sec".format(rNNFrameCount, rNNTotalTime))
    print('Accuracy: %f' % ((TP+TN)/float(TP+FP+TN+FN)))
def main():
    video_fname = "/data/dataset/jackson-town-square.mp4"
    csv_in = "/data/dataset/jackson-town-square.csv"
    avg_fname = "/data/dataset/jackson-town-square.npy"
    avg_fname_orig = "/data/dataset/jackson-town-square_400_600.npy"
    num_frames = 2000
    start_frame = 5001
    target = 'car'

    # Param: difference detector
    dist_metric = 'mse'
    thresh = 0.00024391713548410724
    frame_delay = 1
    feature_fn = RawImage.compute_feature
    get_distance_fn = RawImage.get_distance_fn

    # Param: specialized NN
    c_low = 0.1
    c_high = 0.9

    data, nb_classes = dataPrep.get_data_for_test(csv_in,
                                                  video_fname,
                                                  avg_fname,
                                                  num_frames=num_frames,
                                                  start_frame=start_frame,
                                                  OBJECTS=[target],
                                                  resol=(50, 50),
                                                  shiftEn=1)
    X, Y = data

    origData, orig_nb_classes = dataPrep.get_data_for_test(
        csv_in,
        video_fname,
        avg_fname_orig,
        num_frames=num_frames,
        start_frame=start_frame,
        OBJECTS=[target],
        resol=(608, 608),
        shiftEn=0)
    origX, origY = origData

    meta_f = open('yolo.meta', 'r')
    metadata = json.loads(meta_f.read())

    # Run Difference Detector, and generate index of frames which need Specialized NN

    start = time.time()

    todos = [0]
    for i in range(1, len(X)):
        features = get_features(feature_fn, X[i - 1:i + 1])
        dists = get_distances(get_distance_fn(dist_metric), features,
                              frame_delay)
        if dists > thresh:
            todos.append(i)

    X_new = X[todos]
    origX_new = origX[todos]

    loop = asyncio.get_event_loop()
    results = loop.run_until_complete(
        sendAllRequests(metadata, X_new, origX_new, c_low, c_high, target))
    print(time.time() - start)