Skip to content

Commit db5e937

Browse files
authored
Updated deploy script to usb mdt to deploy over USB (#37)
* Updated deploy script to usb mdt to deploy over USB
1 parent 9f5bf63 commit db5e937

File tree

2 files changed

+43
-11
lines changed

2 files changed

+43
-11
lines changed

learn_ml/deploy/deploy.py

+40-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,17 @@
1515
from scp import SCPClient
1616
import argparse
1717
import os
18+
from mdt.discoverer import Discoverer
19+
from learn_ml.utils.log_configurator import LogConfigurator
1820

21+
DEFAULT_USERNAME = "mendel"
22+
DEFAULT_PASSWORD = "mendel"
23+
24+
# Instantiate LogConfigurator
25+
log_config = LogConfigurator()
26+
27+
# Get the logger for module
28+
logger = log_config.get_logger(__name__)
1929

2030
def deploy(address, model, identity_file=None, password=None):
2131
""" Deploys the a model to the Coral Board.
@@ -41,46 +51,65 @@ def deploy(address, model, identity_file=None, password=None):
4151
use_key = False
4252
if(identity_file is not None):
4353
use_key = True
44-
elif(password is None): # This condition means that neither identity file nor password was passed
54+
elif(password is None):
4555
raise Exception("Must pass identity file OR password")
4656

4757
ssh = SSHClient()
4858
ssh.load_system_host_keys()
4959

5060
# Connect to coral
51-
print("Connecting...")
61+
logger.info("Connecting to Anything Sensor...")
5262
if(use_key): # Connect using private key
53-
ssh.connect(hostname=address, username="mendel", key_filename=identity_file)
63+
ssh.connect(hostname=address, username=DEFAULT_USERNAME, key_filename=identity_file)
5464
else: # Connect using password
55-
ssh.connect(hostname=address, username="mendel", password=password)
56-
print("Successfully connected to Anything Sensor v1!")
65+
ssh.connect(hostname=address, username=DEFAULT_USERNAME, password=password)
66+
logger.info("Successfully connected to Anything Sensor v1!")
5767

5868
# Transfer model to coral
59-
print("Transferring model to Anything Sensor...")
69+
logger.info("Transferring model to Anything Sensor...")
6070
# SCPCLient takes a paramiko transport as an argument
6171
with SCPClient(ssh.get_transport()) as scp:
6272
scp.put(model, "/home/mendel/learn_ml/coral_inference/classification/" + os.path.basename(model))
63-
print("Transfer Successful!")
73+
logger.info("Transfer Successful!")
6474

6575
# Start model execution
6676
ssh.exec_command("pkill screen")
6777
ssh.exec_command("cd /home/mendel/learn_ml/coral_inference/classification && screen -d -m python3 "
6878
+ "app.py --mnist -m " + os.path.basename(model))
6979

70-
print("Started execution!")
71-
print("Stream accessible at {}:5000".format(address))
80+
logger.info("Started execution!")
81+
logger.info("Stream accessible at {}:5000".format(address))
7282

7383
ssh.close()
7484

85+
def deploy_usb(model):
86+
# Import a discoverer object from mendel development tools
87+
discoverer = Discoverer()
88+
89+
# Discover available objects and get available devices
90+
discoverer.discover()
91+
discoveries = discoverer.discoveries
92+
93+
# TODO Update this to allow for selecting between multiple available devices
94+
if(list(discoveries) != []):
95+
# Just select the first element in the dictionary
96+
ip = discoveries[list(discoveries)[0]]
97+
logger.info("Found Anything Sensor at {}!".format(ip))
98+
deploy(ip, model, password = DEFAULT_PASSWORD)
99+
75100

76101
if __name__ == "__main__":
77102
# Parse arguments
78103
parser = argparse.ArgumentParser()
79104
parser.add_argument('-m', '--model', help='Path to .tflite model file', required=True)
80-
parser.add_argument('-a', '--address', help='Address of the coral device', required=True)
105+
parser.add_argument('-a', '--address', help='Address of the coral device', required=False)
81106
parser.add_argument('-i', '--identity-file',
82107
help='Identity file to authenticate with', required=False)
83108
parser.add_argument('-p', '--password', help='Password to login with', required=False)
109+
parser.add_argument('-u', '--usb', help='Deploy over USB', required=False, action = 'store_true')
84110
args = parser.parse_args()
85111

86-
deploy(args.address, args.model, identity_file=args.identity_file, password=args.password)
112+
if(args.usb):
113+
deploy_usb(args.model)
114+
else:
115+
deploy(args.address, args.model, identity_file=args.identity_file, password=args.password)

requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ PySide2
1111
Qt.py
1212
nine
1313
singleton-decorator
14+
mendel-development-tool
15+
typing
16+
zeroconf

0 commit comments

Comments
 (0)