[acd362]: / Projects / NCS1 / Classes / Movidius.py

Download this file

92 lines (65 with data), 2.7 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
############################################################################################
#
# Project: Peter Moss Acute Myeloid & Lymphoblastic Leukemia AI Research Project
# Repository: ALL Detection System 2019
# Project: Facial Authentication Server
#
# Author: Adam Milton-Barker (AdamMiltonBarker.com)
# Contributors:
# Title: Movidius NCS1 Class
# Description: Movidius NCS1 class for the ALL Detection System 2019 NCS1 Classifier.
# License: MIT License
# Last Modified: 2020-07-16
#
# NCS1 API: https://movidius.github.io/ncsdk/ncapi/ncapi1/py_api/readme.html
#
############################################################################################
import cv2
import json
import os
from mvnc import mvncapi as mvnc
from Classes.Helpers import Helpers
class Movidius():
""" ALL Detection System 2019 NCS1 Classifier Movidius Class
Movidius NCS1 functions for the ALL Detection System 2019 NCS1
Classifier.
"""
def __init__(self):
""" Initializes the Movidius Class """
self.Helpers = Helpers("Movidius")
self.confs = self.Helpers.confs
self.classes = []
self.ncsGraph = None
self.ncsDevice = None
self.reqsize = None
self.mean = 128
self.std = 1 / 128
self.Helpers.logger.info("Movidius class initialization complete.")
def checkNCS(self):
""" Checks for NCS devices
Returns True if devices are found else quits """
ncsDevices = mvnc.EnumerateDevices()
if len(ncsDevices) == 0:
self.Helpers.logger.error("No NCS1 devices found.")
quit()
self.ncsDevice = mvnc.Device(ncsDevices[0])
self.ncsDevice.OpenDevice()
self.Helpers.logger.info("Connected To NCS1 successfully.")
return True
def allocateGraph(self, graphfile):
""" Allocate a graph using path to graph file """
self.ncsGraph = self.ncsDevice.AllocateGraph(graphfile)
self.Helpers.logger.info("Movidius graph allocated successfully.")
def loadInception(self):
""" Loads the Inception graph and classes """
self.reqsize = self.confs["Classifier"]["ImageSize"]
with open(self.confs["Classifier"]["InceptionGraph"], mode='rb') as f:
ncsGraphFile = f.read()
self.allocateGraph(ncsGraphFile)
with open(self.confs["Classifier"]["DatasetDir"] + "/" + self.confs["Classifier"]["Classes"], 'r') as f:
for line in f:
cat = line.split('\n')[0]
if cat != 'classes':
self.classes.append(cat)
f.close()
self.Helpers.logger.info("Inception loaded successfully.")