15
15
from scp import SCPClient
16
16
import argparse
17
17
import os
18
+ from mdt .discoverer import Discoverer
19
+ from learn_ml .utils .log_configurator import LogConfigurator
18
20
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__ )
19
29
20
30
def deploy (address , model , identity_file = None , password = None ):
21
31
""" Deploys the a model to the Coral Board.
@@ -41,46 +51,65 @@ def deploy(address, model, identity_file=None, password=None):
41
51
use_key = False
42
52
if (identity_file is not None ):
43
53
use_key = True
44
- elif (password is None ): # This condition means that neither identity file nor password was passed
54
+ elif (password is None ):
45
55
raise Exception ("Must pass identity file OR password" )
46
56
47
57
ssh = SSHClient ()
48
58
ssh .load_system_host_keys ()
49
59
50
60
# Connect to coral
51
- print ("Connecting..." )
61
+ logger . info ("Connecting to Anything Sensor ..." )
52
62
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 )
54
64
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!" )
57
67
58
68
# Transfer model to coral
59
- print ("Transferring model to Anything Sensor..." )
69
+ logger . info ("Transferring model to Anything Sensor..." )
60
70
# SCPCLient takes a paramiko transport as an argument
61
71
with SCPClient (ssh .get_transport ()) as scp :
62
72
scp .put (model , "/home/mendel/learn_ml/coral_inference/classification/" + os .path .basename (model ))
63
- print ("Transfer Successful!" )
73
+ logger . info ("Transfer Successful!" )
64
74
65
75
# Start model execution
66
76
ssh .exec_command ("pkill screen" )
67
77
ssh .exec_command ("cd /home/mendel/learn_ml/coral_inference/classification && screen -d -m python3 "
68
78
+ "app.py --mnist -m " + os .path .basename (model ))
69
79
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 ))
72
82
73
83
ssh .close ()
74
84
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
+
75
100
76
101
if __name__ == "__main__" :
77
102
# Parse arguments
78
103
parser = argparse .ArgumentParser ()
79
104
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 )
81
106
parser .add_argument ('-i' , '--identity-file' ,
82
107
help = 'Identity file to authenticate with' , required = False )
83
108
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' )
84
110
args = parser .parse_args ()
85
111
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 )
0 commit comments