Video ea Cloud Object Detector ho Raspberry Pi

Prologue

Hona joale video e ntse e potoloha Inthaneteng e bontšang hore na autopilot ea Tesla e bona tsela joang.

Ke 'nile ka hlohlona ka nako e telele ho phatlalatsa video e ntlafalitsoeng ka mochine,' me ka nako ea sebele.

Video ea Cloud Object Detector ho Raspberry Pi

Bothata ke hore ke batla ho phatlalatsa video ho tloha Raspberry, 'me ts'ebetso ea neural network detector ho eona e siea lintho tse ngata tse lakatsehang.

Intel Neural Computer Stick

Ke ile ka nahana ka litharollo tse fapaneng.

В sengoloa sa ho qetela e lekile ka Intel Neural Computer Stick. Hardware e matla, empa e hloka sebopeho sa eona sa marang-rang.

Leha Intel e fana ka li-converter bakeng sa meralo e meholo, ho na le maraba a mangata.

Ka mohlala, sebopeho sa marang-rang se hlokahalang se ka 'na sa se ke sa lumellana,' me haeba se lumellana, likarolo tse ling li ka 'na tsa se ke tsa tšehetsoa ho sesebelisoa,' me haeba li tšehetsoa, ​​​​joale liphoso li ka 'na tsa etsahala nakong ea phetoho, ka lebaka leo. re fumana lintho tse makatsang ka tlhahiso.

Ka kakaretso, haeba u batla mofuta o mong oa marang-rang a marang-rang a marang-rang, joale e ka 'na ea se ke ea sebetsa le NCS. Ka hona, ke ile ka etsa qeto ea ho leka ho rarolla bothata ka ho sebelisa lisebelisoa tse atileng haholo le tse fumanehang.

Leru

Mokhoa o mong o hlakileng oa tharollo ea lisebelisoa tsa lehae ke ho ea marung.

Likhetho tse itokiselitseng - mahlo a ka a hlaha.

Baetapele bohle:

... Le ba bangata ba sa tsejweng hakaalo.

Ho khetha har'a mefuta ena e fapaneng ha ho bonolo ho hang.

'Me ke nkile qeto ea ho se khethe, empa ho thatela leano le letle la ho sebetsa ho OpenCV ho Docker le ho le tsamaisa ka leru.

Molemo oa mokhoa ona ke ho feto-fetoha ha maemo le ho laola - o ka fetola marang-rang a neural, hosting, seva - ka kakaretso, leha e le efe e batlang.

Seva

Ha re qaleng ka mohlala oa lehae.

Ka tloaelo ke sebelisa Flask bakeng sa marang-rang a REST API, OpenCV le MobileSSD.

Kaha ke kentse liphetolelo tsa hona joale ho Docker, ke ile ka fumana hore OpenCV 4.1.2 ha e sebetse le Mobile SSD v1_coco_2018_01_28, 'me ke ile ka tlameha ho khutlela ho 11/06_2017 e netefalitsoeng.

Qalong ea ts'ebeletso, re kenya mabitso a sehlopha le marang-rang:

def init():
    tf_labels.initLabels(dnn_conf.DNN_LABELS_PATH)
    return cv.dnn.readNetFromTensorflow(dnn_conf.DNN_PATH, dnn_conf.DNN_TXT_PATH)

Ho docker ea lehae (ho laptop e seng nyane haholo) ho nka metsotsoana e 0.3, ho Raspberry - 3.5.

Ha re qale ho bala:

def inference(img):
    net.setInput(cv.dnn.blobFromImage(img, 1.0/127.5, (300, 300), (127.5, 127.5, 127.5), swapRB=True, crop=False))
    return net.forward()

Docker - 0.2 sec, Raspberry - 1.7.

Ho fetola tensor exhaust hore e be json e baloang:

def build_detection(data, thr, rows, cols):
    ret = []
    for detection in data[0,0,:,:]:
        score = float(detection[2])
        if score > thr:
            cls = int(detection[1])
            a = {"class" : cls, "name" : tf_labels.getLabel(cls),  "score" : score}
            a["x"] = int(detection[3] * cols)
            a["y"] = int(detection[4] * rows)
            a["w"] = int(detection[5] * cols ) - a["x"]
            a["h"] = int(detection[6] * rows) - a["y"]
            ret.append(a)
    return ret

Ntle le moo romela ts'ebetso ena ka Flask(kenyeletso ke setšoantšo, tlhahiso ke liphetho tsa detector ho json).

Khetho e 'ngoe, eo ho eona mosebetsi o mongata o fetisetsoang ho seva: eona ka boeona e potoloha lintho tse fumanoeng ebe e khutlisa setšoantšo se phethiloeng.

Khetho ena e ntle moo re sa batleng ho hula opencv ho seva.

Docker

Re bokella setšoantšo.

Khoutu e hlakotsoe ebe e romelloa Github, docker e tla e nka ka kotloloho ho tloha moo.

Joalo ka sethala, re tla nka Debian Stretch e ts'oanang le ea Raspberry - re ke ke ra kheloha tekhenoloji e netefalitsoeng.

U hloka ho kenya botlolo, protobuf, likopo, opencv_python, download Mobile SSD, khoutu ea seva ho tloha Github le ho qala seva.

FROM python:3.7-stretch

RUN pip3 install flask
RUN pip3 install protobuf
RUN pip3 install requests
RUN pip3 install opencv_python

ADD http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_11_06_2017.tar.gz /
RUN tar -xvf /ssd_mobilenet_v1_coco_11_06_2017.tar.gz

ADD https://github.com/tprlab/docker-detect/archive/master.zip /
RUN unzip /master.zip

EXPOSE 80

CMD ["python3", "/docker-detect-master/detect-app/app.py"]

E bonolo detector client e thehiloeng likopong.

Ho phatlalatsa ho Docker Hub

Lingoliloeng tsa Docker li ntse li ata ka lebelo le ka tlase ho li-detectors tsa maru.

E le hore re se ke ra khathatseha, re tla feta ka mokhoa o tsitsitseng DockerHub.

  1. Ngodisa
  2. Kena:
    ho kena ha docker
  3. Ha re hlahise lebitso le nang le moelelo:
    docker tag opencv-detect tprlab/opencv-detect-ssd
  4. Kenya setšoantšo ho seva:
    docker push tprlab/opencv-detect-ssd

Re qala marung

Khetho ea hore na u ka tsamaisa setshelo hokae le eona e pharaletse haholo.

Libapali tsohle tse kholo (Google, Microsoft, Amazon) li fana ka li-micro-instance mahala bakeng sa selemo sa pele.
Kamora ho etsa liteko ka Microsoft Azure le Google Cloud, ke ile ka lula ho eona hobane e ile ea tloha kapele.

Ha kea ngola litaelo mona, kaha karolo ena e tobile haholo ho mofani ea khethiloeng.

Ke lekile likhetho tse fapaneng tsa Hardware,
Maemo a tlase (a arolelanoeng le a inehetseng) - 0.4 - 0.5 metsotsoana.
Likoloi tse matla ho feta - 0.25 - 0.3.
Leha ho le joalo, esita le maemong a mabe ka ho fetesisa, meputso ke makhetlo a mararo, o ka leka.

Видео

Re hlahisa video e bonolo ea OpenCV ho Raspberry, e lemoha ka Google Cloud.
Bakeng sa teko, ho ile ha sebelisoa faele ea video e kileng ea nkuoa sebakeng se sa reroang.


def handle_frame(frame):
    return detect.detect_draw_img(frame)
       
def generate():
    while True:
        rc, frame = vs.read()
        outFrame = handle_frame(frame)
        if outFrame is None:
            (rc, outFrame) = cv.imencode(".jpg", frame)
        yield(b'--framern' b'Content-Type: image/jpegrnrn' + bytearray(outFrame) + b'rn')

@app.route("/stream")
def video_feed():
    return Response(generate(), mimetype = "multipart/x-mixed-replace; boundary=frame")

Ka detector ha re fumane liforeimi tse fetang tse tharo ka motsotsoana, ntho e 'ngoe le e' ngoe e tsamaea butle haholo.
Haeba o kenya mochini o matla ho GCloud, o ka bona liforeimi tse 4-5 motsotsoana, empa phapang e batla e sa bonahale mahlong, e ntse e tsamaea butle.

Video ea Cloud Object Detector ho Raspberry Pi

Leru le litšenyehelo tsa lipalangoang ha li amane le eona; detector e sebetsa ka lisebelisoa tse tloaelehileng 'me e sebetsa ka lebelo le joalo.

Neural Computer Stick

Ke ne ke sa khone ho hanela mme ka tsamaisa benchmark ho NCS.

Lebelo la detector le ne le le butle ho feta metsotsoana e 0.1, leha ho le joalo ka makhetlo a 2-3 ho feta leru ka mochine o fokolang, ke hore liforeimi tse 8-9 motsotsoana.

Video ea Cloud Object Detector ho Raspberry Pi

Phapang ea liphetho e hlalosoa ke taba ea hore NCS e ne e sebelisa mofuta oa Mobile SSD 2018_01_28.

PS Ho feta moo, liteko li bonts'itse hore mochini o matla oa desktop o nang le processor ea I7 o bonts'a liphetho tse betere hanyane mme ho ile ha fumaneha hore o ka pepeta liforeimi tse 10 motsotsoana ho ona.

Cluster

Teko e ile ea fetela pele mme ke ile ka kenya detector ho li-node tse hlano ho Google Kubernetes.
Li-pods ka botsona li ne li fokola 'me e' ngoe le e 'ngoe ea tsona e ne e sitoa ho sebetsana le liforeimi tse fetang 2 motsotsoana.
Empa haeba u tsamaisa sehlopha se nang le li-node tsa N le liforeimi tsa ho arola ka likhoele tsa N, joale ka palo e lekaneng ea li-node (5) u ka finyella liforeimi tse 10 tse lakatsehang motsotsoana.

def generate():
    while True:
        rc, frame = vs.read()
        if frame is not None:
            future = executor.submit(handle_frame, (frame.copy()))
            Q.append(future)

        keep_polling = len(Q) > 0
        while(keep_polling):            
            top = Q[0]
            if top.done():
                outFrame = top.result()
                Q.popleft()
                if outFrame:
                    yield(b'--framern' b'Content-Type: image/jpegrnrn' + bytearray(outFrame) + b'rn')
                keep_polling = len(Q) > 0
            else:
                keep_polling = len(Q) >= M

Se etsahetseng ke sena:

Video ea Cloud Object Detector ho Raspberry Pi

E potlakile hanyane ho feta ka NCS, empa e matla ho feta molapong o le mong.

Phaello, ehlile, ha e na moeli - ho na le likoahelo tsa ho hokahanya le ho kopitsa ho tebileng ha litšoantšo tsa opencv.

fihlela qeto e

Ka kakaretso, teko e re lumella ho etsa qeto ea hore haeba u leka, u ka baleha ka leru le bonolo.

Empa komporo e matla kapa lisebelisoa tsa lehae li u lumella ho fumana liphetho tse ntle, ntle le maqheka.

litšupiso

Source: www.habr.com

Eketsa ka tlhaloso