scanner-research / scanner

Efficient video analysis at scale
https://scanner-research.github.io/
Apache License 2.0
615 stars 108 forks source link

K8s example: ScannerException('Table has not committed yet.') #239

Open jpablomch opened 5 years ago

jpablomch commented 5 years ago

Running the following code raises the exception below:

from scannerpy import Database, DeviceType, Job
from scannerpy.stdlib import pipelines
import subprocess as sp

def main():

    #********* Master

    print('Finding master IP...')
    ip = sp.check_output(
        '''
        kubectl get services scanner-master --output json | jq -r '.status.loadBalancer.ingress[0].hostname'
        ''',
        shell=True).strip().decode('utf-8')

    port = sp.check_output(
        '''
    kubectl get svc/scanner-master -o json | \
    jq '.spec.ports[0].port' -r
    ''',
        shell=True).strip().decode('utf-8')

    master = '{}:{}'.format(ip, port)
    print('Master ip: {:s}'.format(master))

    with open('config.toml', 'w') as f:
        config_text = sp.check_output(
            '''
            kubectl get configmaps scanner-configmap -o json | \
            jq '.data["config.toml"]' -r
            ''',
            shell=True).strip().decode('utf-8')
        f.write(config_text)

    print('Connecting to Scanner database...')

    db = Database(
        master=master,
        start_cluster=False,
        config_path='./config.toml',
        grpc_timeout=120)

    print('Ingesting video into Scanner ...')

    movie_path = 'sample-clip-supershort.mp4'
    movie_name = 'sample-clip-supershort'

    [input_table], _ = db.ingest_videos(
        [(movie_name, movie_path)], force=True)

    sampler = db.streams.All
    sampler_args = {}

    print('Detecting faces...')
    [bboxes_table] = pipelines.detect_faces(
        db, [input_table.column('frame')],
        sampler,
        sampler_args,
        movie_name + '_bboxes')

    print('Drawing faces onto video...')
    frame = db.sources.FrameColumn()
    sampled_frame = sampler(frame)
    bboxes = db.sources.Column()
    out_frame = db.ops.DrawBox(frame=sampled_frame, bboxes=bboxes)
    output = db.sinks.Column(columns={'frame': out_frame})
    job = Job(op_args={
        frame: input_table.column('frame'),
        sampled_frame: sampler_args,
        bboxes: bboxes_table.column('bboxes'),
        output: movie_name + '_bboxes_overlay',
    })
    [out_table] = db.run(output=output, jobs=[job], force=True)
    out_table.column('frame').save_mp4(movie_name + '_faces')

    print('Successfully generated {:s}_faces.mp4'.format(movie_name))

if __name__ == "__main__":
    main()

Exception : Traceback (most recent call last): File "simple_face_k8s.py", line 81, in main() File "simple_face_k8s.py", line 61, in main movie_name + '_bboxes') File "/home/ubuntu/.local/lib/python3.5/site-packages/scannerpy/stdlib/pipelines.py", line 135, in detectfaces profilers['scale{}'.format(scale)] = output[0].profiler() File "/home/ubuntu/.local/lib/python3.5/site-packages/scannerpy/table.py", line 102, in profiler raise ScannerException('Table has not committed yet.') scannerpy.common.ScannerException: Table has not committed yet.