def process(self): try: self.progress.emit('Проверка имени пользователя и пароля') if not self.checkAuth(): self.progress.emit( '<font color=red>Неверное имя пользователя и/или пароль</font>' ) self.finished.emit() return self.progress.emit( 'Синхронизация локального хранилища с сервером...') for client in Options.get().local_clients: Models.get().clients.saveItem(client) for application in Options.get().local_applications: Models.get().applications.saveItem(application) Options.get().local_clients = [] Options.get().local_applications = [] self.progress.emit('Загрузка типов заявок') Models.get().application_types.loadData() self.progress.emit('Загрузка заказчиков') Models.get().clients.loadData() self.progress.emit('Загрузка специалистов') Models.get().specialists.loadData() self.progress.emit('') self.result.emit(True) except requests.exceptions.ConnectionError: self.result.emit(False) self.finished.emit()
def autonomy_mode(self): Options.get().autonomy_mode = True Models.get().application_types.setItems( Options.get().cache_application_types) Models.get().clients.setItems(Options.get().cache_clients) Models.get().specialists.setItems(Options.get().cache_specialists) self.accept()
def __init__(self, options=None, title='EmdrosApplication', DO_REF=True, DO_OUT=True, DO_LBL=True): if options is None: options = Options() kernel_cfg_name = options.get('kernel') if kernel_cfg_name is not None: kernel_cfg_name = 'emdros_application.syscfg.' + re.sub( '\.py[c]?$', '', kernel_cfg_name) else: kernel_cfg_name = syscfg.config.DEFAULT_KERNEL import importlib kernel = importlib.import_module(kernel_cfg_name) self.kernel = kernel #kernel = __import__(kernel_cfg_name) self.title = title self.DO_REF = DO_REF self.DO_OUT = DO_OUT self.DO_LBL = DO_LBL self.title = title self.spinner = Spinner() if options is None: self.options = Options( addPathAndExt('options', kernel.CFG_DIR, kernel.CFG_EXT)) else: self.options = options self.cfg = self.configure(self.options, kernel) self.modeCfgs = self.setupModeConfigurations(kernel) self.mql = MQLEngine(database=self.database, usr=self.usr, pwd=self.pwd, be=self.backend, domainfile=self.domainqueryfile, domain=self.domain, VERBOSE=self.VERBOSE, verbose=self.verbose, test=self.test, outstream=self.outstream, errstream=self.errstream, kernel=kernel) if self.DO_OUT or self.DO_REF: self.ref, self.out = self.setupOutput(kernel=kernel) if self.DO_LBL: self.lbl = self.setupLabelManagers(options.args, kernel=kernel) if self.options.get('gui'): self.gui = GUI(title=title, app=self) self.gui.mainloop() else: self.gui = None
def fetchMore(self, index): headers = {'Authorization': 'Token ' + Options.get().token} try: if not self._next: url = 'http://' + Options.get( ).server_url + '/api/applications/?' if self._search_date: url += 'contract_date=' + self._search_date.toString( 'yyyy-MM-dd') + '&' if self._search_number: url += 'contract_number=' + self._search_number + '&' data = requests.get(url, headers=headers).json() else: data = requests.get(self._next).json() except requests.exceptions.ConnectionError: QMessageBox().warning( None, 'Ошибка', 'Соединение с сервером потеряно. Программа будет закрыта.') die() return self.beginInsertRows(QModelIndex(), len(self._items), len(self._items) + len(data['results']) - 1) for item in data['results']: self._items.append(Application.fromDict(item)) self.endInsertRows() self._next = data['next'] self._has_next_page = bool(data['next'])
def loadData(cls): headers = {'Authorization': 'Token ' + Options.get().token} data = requests.get('http://' + Options.get().server_url + '/' + cls.url, headers=headers).json() cls._items = [] for item in data: cls._items.append(cls.item_class.fromDict(item))
def checkAuth(self): data = requests.post('http://' + Options.get().server_url + '/api/auth/', json={ 'username': self.username, 'password': self.password }).json() if data['status'] != 'success': return False Options.get().token = data['token'] Options.get().group = data['user']['group'] return True
def login(self): Options.get().username = self.ui.edtUsername.text() self.ui.btnAutonomyMode.setEnabled(False) self.ui.btnLogin.setEnabled(False) self.loadModels()
def loadOptions(self): '''create the self.options object from values stored in the settings''' self.options = Options() for opt, dflt in zip(self.options.optlist, self.options.dfltlist): if isinstance(dflt, (str, unicode)): setattr( self.options, opt, unicode( self.settings.value( 'Options/' + opt, QtCore.QVariant(QtCore.QString(dflt))).toString())) elif isinstance(dflt, float): setattr( self.options, opt, self.settings.value('Options/' + opt, QtCore.QVariant(dflt)).toDouble()[0]) elif isinstance(dflt, bool): setattr( self.options, opt, self.settings.value('Options/' + opt, QtCore.QVariant(dflt)).toBool()) elif isinstance(dflt, int): setattr( self.options, opt, self.settings.value('Options/' + opt, QtCore.QVariant(dflt)).toInt()[0]) else: raise ValueError('Unsupported type in option "%s"' % dflt)
def __init__(self): super(ApplicationModel, self).__init__() self._items = Options.get().local_applications.copy() self._next = None self._has_next_page = True self._search_date = None self._search_number = None
def add_process(self, process, quiet): if not quiet and Options.auto_show_process_window(): self.show_process(process) (first_line, _) = self.__command_window.write(CommandWindowProcessFormat(process)) self.__command_window_line_maps[process.get_pid()] = first_line + 1 self.__command_window_line_map_order.append(process.get_pid())
def evaluate(): if mx.context.num_gpus() > 0: ctx = mx.gpu() else: ctx = mx.cpu(0) # loading configs args = Options().parse() cfg = Configs(args.config_path) # set logging level logging.basicConfig(level=logging.INFO) # images content_image = tensor_load_rgbimage(cfg.content_image, ctx, size=cfg.val_img_size, keep_asp=True) style_image = tensor_load_rgbimage(cfg.style_image, ctx, size=cfg.val_style_size) style_image = preprocess_batch(style_image) # model style_model = Net(ngf=cfg.ngf) style_model.collect_params().load(cfg.val_model, ctx=ctx) # forward output = style_model(content_image, style_image) # save img tensor_save_bgrimage(output[0], cfg.output_img) logging.info("Save img to {}".format(cfg.output_img))
def get_estimator(): opt = Options() model_dir = "./cnn_model/hist_len_{}_pob_siz_{}_cub_siz_{}".format( opt.hist_len, opt.pob_siz, opt.cub_siz) return tf.estimator.Estimator(model_fn=cnn.cnn_model_fn, model_dir=model_dir)
def saveItem(cls, item): headers = {'Authorization': 'Token ' + Options.get().token} try: if item.id is None: data = requests.post('http://' + Options.get().server_url + '/' + cls.url, json=item.toDict(), headers=headers).json() item.id = data['id'] else: requests.put('http://' + Options.get().server_url + '/' + cls.url + str(item.id) + '/', json=item.toDict(), headers=headers) return True except requests.exceptions.ConnectionError: return False
def search(self, number=None, date=None): self._search_date = date self._search_number = number self.beginResetModel() self._next = None self._has_next_page = True self._items = Options.get().local_applications.copy() self.endResetModel()
def show_process(self, process): log("showing process output: %s" % process.get_pid()) self.__process_window_process = process self.__process_window.clean() self.__process_window_output_line = 0 self.__process_window.create(Options.new_process_window_command()) self.__process_window.write(ProcessWindowHeaderFormat(process)) self.__write_output(process.output().all())
def setupContract(self): has_perms = Options.get().group in ('supervisor', 'accounting') if self.currentApplication().contract is not None: self.ui.btnEditContract.setEnabled(has_perms) self.ui.btnCreateContract.setEnabled(False) self.ui.btnPrintContract.setEnabled(True) self.ui.lblContractNumber.setText('№%s' % self.currentApplication().contract.number) else: self.ui.btnEditContract.setEnabled(False) self.ui.btnCreateContract.setEnabled(has_perms) self.ui.btnPrintContract.setEnabled(False) self.ui.lblContractNumber.setText('не создан')
def get_data(opt=Options()): sim = Simulator(opt.map_ind, opt.cub_siz, opt.pob_siz, opt.act_num) states = np.zeros([opt.data_steps, opt.state_siz], float) labels = np.zeros([opt.data_steps], int) # Note I am forcing the display to be off here to make data collection fast # you can turn it on again for debugging purposes # opt.disp_on = False # 1. control loop if opt.disp_on: win_all = None win_pob = None epi_step = 0 # #steps in current episode nepisodes = 1 # total #episodes executed state = sim.newGame(opt.tgt_y, opt.tgt_x) for step in range(opt.data_steps): if state.terminal or epi_step >= opt.early_stop: epi_step = 0 nepisodes += 1 state = sim.newGame(opt.tgt_y, opt.tgt_x) else: state = sim.step() # will perform A* actions # save data & label states[step, :] = rgb2gray(state.pob).reshape(opt.state_siz) labels[step] = state.action epi_step += 1 if step % opt.prog_freq == 0: print(step) if opt.disp_on: if win_all is None: import pylab as pl pl.figure() win_all = pl.imshow(state.screen) pl.figure() win_pob = pl.imshow(state.pob) else: win_all.set_data(state.screen) win_pob.set_data(state.pob) pl.pause(opt.disp_interval) pl.draw() # 2. save to disk print('saving data ...') np.savetxt(opt.states_fil, states, delimiter=',') np.savetxt(opt.labels_fil, labels, delimiter=',') print("states saved to " + opt.states_fil) print("labels saved to " + opt.labels_fil)
def plt_heat_map_results(plt_file_name = None): opt = Options() opt.disp_on = False pob_siz_len = np.arange(start=3, stop=11,step=2) #not even steps needed hist_len = np.arange(start=1, stop=5) # pob_siz_len =[5,3,5,9,1] results_success_rate_map_zero = [] results_astar_diff = [] cnt_Test=0 with K.get_session(): for p in pob_siz_len: opt.pob_siz = p opt.state_siz = (p * opt.cub_siz) ** 2 print("start with opt.pob_siz: {}".format(opt.pob_siz)) print("start with opt.state_siz: {}".format(opt.state_siz)) # get_data(opt)#generaten new data for l in hist_len: opt.hist_len = l print("start with opt.hist_len: {}".format(opt.hist_len)) # train_model(opt, mdl_name,epochs=EPOCHS) # [success_rate, astar_diff] = test_model(opt,mdl_name) # results_success_rate_map_zero.append(success_rate) results_success_rate_map_zero.append(cnt_Test) cnt_Test1+=1 # results_astar_diff.append(astar_diff) results_success_rate_map_zero=np.array(results_success_rate_map_zero) plt.imshow(results_success_rate_map_zero.reshape(len(pob_siz_len),len(hist_len)), cmap='hot', interpolation='nearest') plt.colorbar() # plt.show() helper_save(plt_file_name)
def plt_pob_siz_results(plt_file_name = None): mdl_name = "list_len_mdl.h5" opt = Options() pob_siz_len = np.arange(start=3, stop=11,step=2) #not even steps needed # pob_siz_len =[5,3,5,9,1] results_success_rate_map_zero = [] results_astar_diff = [] for p in pob_siz_len: opt.pob_siz = p opt.state_siz = (p * opt.cub_siz) ** 2 print("start with opt.pob_siz: {}".format(opt.pob_siz)) print("start with opt.state_siz: {}".format(opt.state_siz)) map_ind = opt.map_ind opt.map_ind = 0 get_data(opt)#generaten new data with the map 0 opt.map_ind = map_ind train_model(opt, mdl_name, epochs=EPOCHS) [success_rate, astar_diff] = test_model(opt,mdl_name) results_success_rate_map_zero.append(success_rate) results_astar_diff.append(astar_diff) # Four polar axes f, axarr = plt.subplots(1,2) axarr[0].scatter(pob_siz_len, results_success_rate_map_zero) axarr[0].set_ylabel(r'success rate',usetex=True) axarr[1].scatter(pob_siz_len, results_astar_diff) # axarr[1].set_title('difference to astar in number of steps') axarr[1].set_ylabel(r'mean difference to astar in steps',usetex=True) axarr[0].set_xlabel(r'view size',usetex=True) axarr[1].set_xlabel(r'view size',usetex=True) helper_save(plt_file_name)
def main(unused_argv): opt = Options() sim = Simulator(opt.map_ind, opt.cub_siz, opt.pob_siz, opt.act_num) trans = TransitionTable(opt.state_siz, opt.act_num, opt.hist_len, opt.minibatch_size, opt.valid_size, opt.states_fil, opt.labels_fil) # 1. train ###################################### # TODO implement your training here! # you can get the full data from the transition table like this: # # # both train_data and valid_data contain tupes of images and labels train_data = trans.get_train() valid_data = trans.get_valid() samples_train_data = np.float32(train_data[0]) labels_train_data = np.float32(train_data[1]) unhotted_labels_train_data = unhot(labels_train_data) samples_valid_data = np.float32(valid_data[0]) labels_valid_data = np.float32(valid_data[1]) unhotted_labels_valid_data = unhot(labels_valid_data) print("Shape of samples_train_data {}".format(samples_train_data.shape)) print("Shape of labels_train_data {}".format(labels_train_data.shape)) print("Shape of unhotted_labels_train_data {}".format(unhotted_labels_train_data.shape)) classifier = cnn.get_estimator() # Train the model train_input_fn = tf.estimator.inputs.numpy_input_fn( x={"x": samples_train_data}, y=unhotted_labels_train_data, batch_size=100, num_epochs=None, shuffle=True) classifier.train( input_fn=train_input_fn, steps=1000 ) eval_input_fn = tf.estimator.inputs.numpy_input_fn( x={"x": samples_valid_data}, y=unhotted_labels_valid_data, num_epochs=1, shuffle=False ) eval_results = classifier.evaluate(input_fn=eval_input_fn) print(eval_results)
def tblApplicationsSelectionChanged(self, selected, deselected): if len(self.ui.tblApplications.selectedIndexes()): self.ui.btnEditApplication.setEnabled(not Options.get().autonomy_mode) self.ui.pnlDocuments.setEnabled(bool(self.currentApplication().id)) self.ui.btnPrintApplication.setEnabled(True) self.setupContract() self.setupAccount() self.setupOrder() self.setupProtocols() else: self.ui.btnEditApplication.setEnabled(False) self.ui.pnlDocuments.setEnabled(False) self.ui.btnPrintApplication.setEnabled(False)
def setupOrder(self): has_perms = self.currentApplication().contract is not None and \ self.currentApplication().account is not None and \ Options.get().group in ('supervisor', 'secretary', 'testing') if self.currentApplication().order is not None: self.ui.btnEditOrder.setEnabled(has_perms) self.ui.btnCreateOrder.setEnabled(False) self.ui.btnPrintOrder.setEnabled(True) self.ui.lblOrderNumber.setText('№%s' % self.currentApplication().order.number) else: self.ui.btnEditOrder.setEnabled(False) self.ui.btnCreateOrder.setEnabled(has_perms) self.ui.btnPrintOrder.setEnabled(False) self.ui.lblOrderNumber.setText('не создан')
def loadModelsFinished(self, success): if not success: if Options.get().autonomy_available: ans = QMessageBox().warning( None, 'Ошибка', 'Произошла ошибка при соединении с сервером. Перейти в автономный режим?', QMessageBox.Yes | QMessageBox.No) if ans == QMessageBox.Yes: self.autonomy_mode() return else: QMessageBox().warning( None, 'Ошибка', 'Произошла ошибка при соединении с сервером.', QMessageBox.Ok) self.reset() else: self.accept()
def edit(cls, client, parent=None): from views.client_form import ClientForm dlg = ClientForm(parent) dlg.setClient(client) result = dlg.exec() if result == ClientForm.Accepted: client = dlg.getClient() if not Options.get().autonomy_mode: while not cls.model.saveItem(client): p = QMessageBox().warning( parent, 'Ошибка', 'Потеряно соединение с сервером. Повторить?\nПри отмене программа будет ' 'закрыта, а несохраненные изменения потеряны.', QMessageBox.Retry | QMessageBox.Cancel) if p != QMessageBox.Retry: die() return True return False
def createApplication(self, parent=None): dlg = ApplicationWizard(parent) result = dlg.exec() if result == ApplicationWizard.Accepted: application = dlg.getApplication() if not Options.get().autonomy_mode: while not self.saveItem(application): p = QMessageBox().warning( None, 'Ошибка', 'Потеряно соединение с сервером. Повторить?\nПри отмене программа будет ' 'закрыта, а несохраненные изменения потеряны.', QMessageBox.Retry | QMessageBox.Cancel) if p != QMessageBox.Retry: self.addItem(application) die() self.addItem(application) return True return False
def model(input_shape, model_name='', visualize_model=False): opt = Options() model = Sequential() model.add( Convolution2D(input_shape=input_shape, filters=default_n_filters, kernel_size=default_kernel_size, activation='relu', padding='same', name='ConvLayer1')) model.add(Flatten()) model.add(Dense(512, activation='relu')) model.add(Dense(opt.act_num)) model.compile(loss='mse', metrics=['acc'], optimizer=Adam(lr=1e-6)) if visualize_model: print("Saving model diagram") plot_model(model, to_file=opt.model_path.format(model_name), show_shapes=True) return model
def plt_hist_len_results(plt_file_name = None, opt = Options()): mdl_name = "list_len_mdl.h5" hist_len = np.arange(start=1, stop=11) results_success_rate_map_zero = [] results_astar_diff = [] map_ind = opt.map_ind opt.map_ind = 0 #opt.change_tgt = False get_data(opt)#generaten new data with the map 0 opt.map_ind = map_ind print("map used {}".format(opt.map_ind)) #opt.change_tgt = True for l in hist_len: opt.hist_len = l print("start with opt.hist_len: {}".format(opt.hist_len)) train_model(opt, mdl_name,epochs=EPOCHS) [success_rate, astar_diff] = test_model(opt,mdl_name) results_success_rate_map_zero.append(success_rate) results_astar_diff.append(astar_diff) f, axarr = plt.subplots(1,2) axarr[0].scatter(hist_len, results_success_rate_map_zero) # axarr[0].set_title('map 1') axarr[0].set_ylabel(r'success rate',usetex=True) axarr[1].scatter(hist_len, results_astar_diff) # axarr[1].set_title('map 1') axarr[1].set_ylabel(r'mean difference to astar in steps',usetex=True) axarr[1].set_xlabel(r'history length',usetex=True) axarr[0].set_xlabel(r'history length',usetex=True) # Fine-tune figure; make subplots farther from each other. f.subplots_adjust(hspace=0.3) helper_save(plt_file_name)
"--steps", help="(Optional) Number of steps to train the model for. Default is 1000", type=int, default=1000) parser.add_argument("-ss", "--silent", help="Runs test without displaying the simulation", action="store_false") args = parser.parse_args() model_path = args.model # -------------------------------------------------------- # 0. initialization opt = Options() sim = Simulator(opt.map_ind, opt.cub_siz, opt.pob_siz, opt.act_num) opt.disp_on = args.silent if args.steps: opt.steps = args.steps # -------------------------------------------------------- # Input layer image_dimension = opt.cub_siz * opt.pob_siz img_rows = img_cols = image_dimension input_shape = [img_rows, img_cols, opt.hist_len] # -------------------------------------------------------- # Model
import tensorflow as tf # custom modules from utils import Options from simulator import Simulator from transitionTable import TransitionTable #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # NOTE: # this script assumes you did generate your data with the get_data.py script # you are of course allowed to change it and generate data here but if you # want this to work out of the box first run get_data.py #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # 0. initialization opt = Options() sim = Simulator(opt.map_ind, opt.cub_siz, opt.pob_siz, opt.act_num) trans = TransitionTable(opt.state_siz, opt.act_num, opt.hist_len, opt.minibatch_size, opt.valid_size, opt.states_fil, opt.labels_fil) # 1. train ###################################### # TODO implement your training here! # you can get the full data from the transition table like this: # # # both train_data and valid_data contain tupes of images and labels # train_data = trans.get_train() # valid_data = trans.get_valid() # # alternatively you can get one random mini batch line this
import numpy as np np.random.seed(0) from random import randrange # custom modules from utils import Options, rgb2gray from simulator import Simulator # 0. initialization opt = Options() sim = Simulator(opt.map_ind, opt.cub_siz, opt.pob_siz, opt.act_num) states = np.zeros([opt.data_steps, opt.state_siz], float) labels = np.zeros([opt.data_steps], int) # Note I am forcing the display to be off here to make data collection fast # you can turn it on again for debugging purposes opt.disp_on = False # 1. control loop if opt.disp_on: win_all = None win_pob = None epi_step = 0 # #steps in current episode nepisodes = 1 # total #episodes executed state = sim.newGame(opt.tgt_y, opt.tgt_x) for step in range(opt.data_steps): if state.terminal or epi_step >= opt.early_stop: epi_step = 0 nepisodes += 1 state = sim.newGame(opt.tgt_y, opt.tgt_x) else: