2019-10-23 06:27:11 +03:00
|
|
|
import sys, os, time
|
2020-01-27 00:55:22 +03:00
|
|
|
import rpyc
|
2019-10-23 06:27:11 +03:00
|
|
|
|
2020-07-05 08:33:49 +03:00
|
|
|
from .log import LOGGER
|
|
|
|
from .ServerModelsAbstract import BackendModel
|
|
|
|
from .Utils import serialize, deserialize
|
2019-10-23 06:27:11 +03:00
|
|
|
|
|
|
|
|
|
|
|
class ModelRPC(BackendModel):
|
|
|
|
|
2020-01-27 00:55:22 +03:00
|
|
|
def __init__(self, session_id, port):
|
2019-10-24 01:08:15 +03:00
|
|
|
self.session_id = session_id
|
2019-10-23 08:02:37 +03:00
|
|
|
|
2020-01-27 00:55:22 +03:00
|
|
|
self.max_retries = 30
|
|
|
|
self.rety_timeout = 2
|
|
|
|
self.connection = None
|
|
|
|
|
|
|
|
i=0
|
|
|
|
while self.connection is None or i<self.max_retries:
|
|
|
|
try:
|
|
|
|
self.connection = rpyc.connect("localhost", port, config={
|
|
|
|
'allow_public_attrs': False
|
|
|
|
})
|
|
|
|
LOGGER.info("Made a connection")
|
|
|
|
break
|
|
|
|
except ConnectionRefusedError:
|
|
|
|
i+=1
|
|
|
|
time.sleep(self.rety_timeout)
|
|
|
|
LOGGER.warning("Haven't connected, attempt %d" % (i))
|
2019-10-23 06:27:11 +03:00
|
|
|
|
|
|
|
def run(self, naip_data, extent, on_tile=False):
|
2020-01-27 00:55:22 +03:00
|
|
|
return deserialize(self.connection.root.exposed_run(serialize(naip_data), extent, on_tile))
|
2019-10-23 08:02:37 +03:00
|
|
|
def retrain(self):
|
2020-01-27 00:55:22 +03:00
|
|
|
return self.connection.root.exposed_retrain()
|
2019-10-23 06:27:11 +03:00
|
|
|
def add_sample(self, tdst_row, bdst_row, tdst_col, bdst_col, class_idx):
|
2020-01-27 00:55:22 +03:00
|
|
|
return self.connection.root.exposed_add_sample(tdst_row, bdst_row, tdst_col, bdst_col, class_idx)
|
2019-10-23 06:27:11 +03:00
|
|
|
def undo(self):
|
2020-01-27 00:55:22 +03:00
|
|
|
return self.connection.root.exposed_undo()
|
2019-10-23 06:27:11 +03:00
|
|
|
def reset(self):
|
2020-01-27 00:55:22 +03:00
|
|
|
return self.connection.root.exposed_reset()
|