def __init__(self, parent, path): # take data and use datamanager to return imageSize, and ints. # Attributes self.path = path self.imageNum = 0 # current image in the data to be viewed self.imgSize = DataManager.getImgSize(path, split=True) self.imgSizeX = self.imgSize[1] self.imgSizeY = self.imgSize[0] self.imgSize = DataManager.getImgSize(path, split=False) self.setSize = DataManager.getSetSize(path) # Number of images in set self.currentPixel = None # Tk.Frame obj self.currentPixelPos = None # int position of pixel in current image # Pixel holder self.wrapper = Tk.Frame(parent) self.wrapper.grid(row=0, column=0) self.digitDisplay = Tk.Frame(self.wrapper, width=235, height=235) self.digitDisplay.grid_propagate(False) for i in range(self.imgSizeY): self.digitDisplay.grid_rowconfigure(i, weight=1) for i in range(self.imgSizeX): self.digitDisplay.grid_columnconfigure(i, weight=1) self.digitDisplay.grid(row=0, column=0) # EntryBox self.pixelLabel = Tk.Label(self.wrapper, text='No pixel selected') self.pixelLabel.grid(row=1, column=0, sticky='nswe') # self.pixel is a 2d array containing Tk.Frames. [0] = imageNum, [1] = frames pixel = [] for i in range(self.setSize): pixel.append([]) self.data = DataManager.getImage(self.path, i) for j in range(self.imgSizeX * self.imgSizeY): val = int.from_bytes(self.data[j:j + 1], byteorder='big') pixel[i].append(self.newPixel(val, j)) self.pixel = pixel # Free up some ram self.data = None return
def __init__(self): self.db = DB() self.sys_user = "******" self.data = DataManager() self.market = MarketManager() self.market_attribute = self.market.attribute self.market_attribute_ch = self.market.attribute_ch self.market_target = self.market.target self.upload = UploadManager() self.upload_attribute = self.upload.attribute self.upload_attribute_ch = self.upload.attribute_ch self.calc = CalcManager() self.calc_attribute = self.calc.attribute self.calc_attribute_ch = self.calc.attribute_ch self.user = UserManager() self.user_role_desc = self.user.role_desc self.role_value = self.user.role_value self.dev = DevManager() self.api_help = HelpManager() self.api_status = StatusManager() self.bug = BugManager() self.ip = IPManager() self.release_man = ReleaseManager(release_dir) self.param_man = ParamFormatManager() self.pull_request_man = PullRequestManager() self.manger_email = ["*****@*****.**", "*****@*****.**"] self.jy_log = LogManager()
def newImg(self, path): # Destroy old pixels for i in range(self.setSize): self.data = DataManager.getImage(self.path, i) for j in range(self.imgSizeX * self.imgSizeY): self.pixel[i][j].destroy() # New attributes self.path = path self.imageNum = 0 # current image in the data to be viewed self.imgSize = DataManager.getImgSize(path, split=True) self.imgSizeX = self.imgSize[1] self.imgSizeY = self.imgSize[0] self.imgSize = DataManager.getImgSize(path, split=False) self.setSize = DataManager.getSetSize(path) # Number of images in set self.currentPixel = None # Tk.Frame obj self.currentPixelPos = None # int position of pixel in current image # self.pixel is a 2d array containing Tk.Frames. [0] = imageNum, [1] = frames pixel = [] for i in range(self.setSize): pixel.append([]) self.data = DataManager.getImage(self.path, i) for j in range(self.imgSizeX * self.imgSizeY): val = int.from_bytes(self.data[j:j + 1], byteorder='big') pixel[i].append(self.newPixel(val, j)) self.pixel = pixel # Free up some ram self.data = None return
def baseline(name): data = DataManager(DATASET_PATH + dataset + ".csv") # Wrapper for SKlearn models so that their interface matches metrics_maple and metrics_lime class Wrapper(): def __init__(self, pred): self.pred = pred self.index = 0 def predict(self, x): return self.pred(x) def set_index(self, i): self.index = i def predict_index(self, x): return np.squeeze(self.pred(x)[:, self.index]) if name == "lr": model = LinearRegression() elif name == "dt": model = DecisionTreeRegressor() elif name == "rf": model = RandomForestRegressor() model.fit(data.X_train, data.y_train) predictions = model.predict(data.X_test) acc = mean_squared_error(data.y_test, predictions) if name == "lr": predict_fn = model.predict elif name == "dt" or name == "rf": def predict_fn(x): return np.expand_dims(model.predict(x), 1) wrapper = Wrapper(predict_fn) _, lime_causal_metric, _ = metrics_lime(wrapper, data.X_train, data.X_test) return acc, lime_causal_metric[0]
class ControlManager: def __init__(self): self.db = DB() self.sys_user = "******" self.data = DataManager() self.market = MarketManager() self.market_attribute = self.market.attribute self.market_attribute_ch = self.market.attribute_ch self.market_target = self.market.target self.upload = UploadManager() self.upload_attribute = self.upload.attribute self.upload_attribute_ch = self.upload.attribute_ch self.calc = CalcManager() self.calc_attribute = self.calc.attribute self.calc_attribute_ch = self.calc.attribute_ch self.user = UserManager() self.user_role_desc = self.user.role_desc self.role_value = self.user.role_value self.dev = DevManager() self.api_help = HelpManager() self.api_status = StatusManager() self.bug = BugManager() self.ip = IPManager() self.release_man = ReleaseManager(release_dir) self.param_man = ParamFormatManager() self.pull_request_man = PullRequestManager() self.manger_email = ["*****@*****.**", "*****@*****.**"] self.jy_log = LogManager() def check_user_name_exist(self, user_name, role, check_user_name): if role & self.role_value["user_new"] <= 0: return False, u"用户无权限新建用户" return self.user.check_account_exist(user_name, check_user_name) def new_user(self, user_name, role, nick_name, creator, creator_role): if creator_role & self.role_value["user_new"] <= 0: return False, u"用户无权限新建用户" if creator_role | role > creator_role: return False, u"给新建用户赋予权限过高" return self.user.new(user_name, role, nick_name, creator) def change_password(self, user_name, old_password, new_password): return self.user.change_password(user_name, old_password, new_password) def send_code(self, user_name, password, tel): return self.user.send_code(user_name, password, tel) def bind_tel(self, user_name, password, tel, code): return self.user.bind_tel(user_name, password, tel, code) def get_my_user(self, user_name, role): if role & self.role_value["user_new"] <= 0: return False, u"用户无权限操作用户" return self.user.my_user(user_name) def update_my_user_role(self, role, user_name, my_user, my_user_role): if role & self.role_value["user_new"] <= 0: return False, u"用户无权限操作用户" if role & my_user_role != my_user_role: return False, u"赋予权限过高" return self.user.update_my_user_role(my_user_role, my_user, user_name) def add_my_user_role(self, role, user_name, add_role, add_user_list): if role & self.role_value["user_new"] <= 0: return False, u"用户无权限操作用户" if role & add_role != add_role: return False, u"增加权限过高" return self.user.add_role_my_users(add_role, add_user_list, user_name) def remove_my_user_role(self, role, user_name, remove_role, remove_user_list): if role & self.role_value["user_new"] <= 0: return False, u"用户无权限操作用户" if role & remove_role != remove_role: return False, u"移除权限过高" return self.user.remove_role_my_users(remove_role, remove_user_list, user_name) def get_role_user(self, role): return self.user.get_role_user(role) def get_data(self): return self.data.get() def new_data(self, role, inputuser): if (role & 1) <= 0: return False, u"您的权限不足" result, message = self.data.new(inputuser) return result, message def new_market(self, data_no, market_info, inputuser, role): if (role & 1) <= 0: return False, u"您的权限不足" data_info = self.data.get(data_no) if len(data_info) <= 0: return False, u"数据编号不存在" if data_info[0]["status"] != 0: return False, u"无修改权限" result, message = self.market.new(data_no, market_info, inputuser) if result is False: return False, message result, message = self.data.update(data_no, 1) if result is True: if inputuser != "upload": self.send_email(u"%s添加了市场记录" % inputuser, data_no, market_info, self.market_attribute, self.market_attribute_ch) return True, data_no def new_upload(self, data_no, upload_info, inputuser, role): if (role & 2) <= 0: return False, u"您的权限不足" data_info = self.data.get(data_no) if len(data_info) <= 0: return False, u"数据编号不存在" if data_info[0]["status"] != 1: return False, u"无修改权限" result, message = self.upload.new(data_no, upload_info, inputuser) if result is False: return False, message result, message = self.data.update(data_no, 2) if result is True: self.send_email(u"%s添加了上传记录" % inputuser, data_no, upload_info, self.upload_attribute, self.upload_attribute_ch) return True, "" def new_calc(self, data_no, calc_info, inputuser, role): if (role & 4) <= 0: return False, u"您的权限不足" data_info = self.data.get(data_no) if len(data_info) <= 0: return False, u"数据编号不存在" if data_info[0]["status"] != 2: return False, u"无修改权限" result, message = self.calc.new(data_no, calc_info, inputuser) if result is False: return False, message result, message = self.data.update(data_no, 3) if result is True: if inputuser != "calc": self.send_email(u"%s添加了计算记录" % inputuser, data_no, calc_info, self.calc_attribute, self.calc_attribute_ch) return True, "" def get_market(self, data_no, role): if (role & 1) <= 0: return False, u"您的权限不足" return self.market.select(data_no) def get_upload(self, data_no, role): if (role & 2) <= 0: return False, u"您的权限不足" return self.upload.select(data_no) def get_calc(self, data_no, role): if (role & 4) <= 0: return False, u"您的权限不足" return self.calc.select(data_no) # 针对开发者的应用 def show_operate_auth(self, role): if role & self.role_value["right_new"] < self.role_value["right_new"]: return False, u"您没有权限" return self.dev.get_operate_auth() def list_data_table(self, role): if role & self.role_value["table_look"] <= 0: return False, u"您没有权限" return self.dev.list_table() def get_table_info(self, table_name, role): if role & self.role_value["table_look"] <= 0: return False, u"您没有权限" return self.dev.get_table_info(table_name) def get_right_module(self, role): if role & self.role_value["right_look"] < self.role_value["right_look"]: return False, u"您没有权限" result, info = self.dev.get_right_module() return result, info def get_right_module_role(self, role, module_no): if role & self.role_value["right_look"] < self.role_value["right_look"]: return False, u"您没有权限" result, info = self.dev.get_right_module_role(module_no) return result, info def get_right_action_role(self, role, module_no): if role & self.role_value["right_look"] < self.role_value["right_look"]: return False, u"您没有权限" result, info = self.dev.get_right_action_role(module_no) return result, info def new_right_action(self, user_name, role, module_no, action_desc, min_role): if role & self.role_value["right_new"] < self.role_value["right_new"]: return False, u"您没有权限" result, info = self.dev.new_right_action(module_no, action_desc, min_role, user_name) return result, info def delete_right_action(self, user_name, role, action_no): if role & self.role_value["right_new"] < self.role_value["right_new"]: return False, u"您没有权限" result, info = self.dev.del_right_action(user_name, action_no) return result, info def backup_table(self, user_name, role, t_name, sql_path): return self.dev.backup_table(t_name, sql_path) def register_backup_task(self): return self.dev.register_backup_task() def send_email(self, sub, data_no, info, attribute, attribute_ch): print("strart send email to %s" % self.manger_email) content = sub + "<br>" content += u"数据编号 : %s<br>" % data_no att_len = len(attribute) for index in range(att_len): content += "%s : %s<br>" % (attribute_ch[index], info[attribute[index]]) for email in self.manger_email: my_email.send_mail_thread(email, sub, content) # 针对API HELP的应用 def get_part_api(self, user_name, role): if role & self.role_value["api_look"] <= 0: return False, u"您没有权限" return self.api_help.get_part_api(user_name=user_name) def get_module_list(self, role): if role & self.role_value["api_look"] <= 0: return False, u"您没有权限" return self.api_help.get_module_list() def get_test_env(self, role, env_no_list=None): if role & self.role_value["api_look"] <= 0: return False, u"您没有权限" return self.api_help.get_test_env(env_no_list) def new_api_module(self, role, module_name, module_prefix, module_desc, module_part, module_env): if role & self.role_value["api_module_new"] <= 0: return False, u"您没有权限" return self.api_help.new_api_module(module_name, module_prefix, module_desc, module_part, module_env) def update_api_module(self, role, module_no, module_name, module_prefix, module_desc, module_part, module_env): if role & self.role_value["api_module_new"] <= 0: return False, u"您没有权限" return self.api_help.update_api_module(module_no, module_name, module_prefix, module_desc, module_part, module_env) def delete_api_module(self, role, module_no): if role & self.role_value["api_module_new"] <= 0: return False, u"您没有权限" return self.api_help.del_api_module(module_no) def new_api_info(self, module_no, title, path, method, desc, user_name, role): if role & self.role_value["api_new"] <= 0: return False, u"您没有权限" result, data = self.api_help.new_api_info(module_no, title, path, method, desc) if result is True: self.api_help.new_api_care(data["api_no"], user_name, 0) api_no = data["api_no"] t = Thread(target=self._send_module_message, args=(user_name, module_no, api_no, title, method, desc)) t.start() return result, data def update_api_info(self, role, api_no, module_no, title, path, method, desc): if role & self.role_value["api_new"] <= 0: return False, u"您没有权限" result, data = self.api_help.update_api_info(api_no, module_no, title, path, method, desc) return result, data def get_api_info(self, api_no, role): if role & self.role_value["api_look"] <= 0: return False, u"您没有权限" result, api_info = self.api_help.get_api_info(api_no) if result is True: if role & self.role_value["api_new"] <= 0 and api_info["basic_info"]["stage"] == u'新建': return False, u"您没有权限" return result, api_info def add_header_param(self, user_name, api_no, param, necessary, desc, role): if role & self.role_value["api_new"] <= 0: return False, u"您没有权限" result, info = self.api_help.new_api_header(api_no, {param: {"necessary": necessary, "desc": desc}}) if result is True: self._send_api_update_message_thread(user_name, api_no, param) return result, info def add_predefine_header(self, user_name, api_no, param, param_type, role): if role & self.role_value["api_new"] <= 0: return False, u"您没有权限" result, info = self.api_help.new_predefine_param(api_no, param, param_type) if result is True: self._send_api_update_message_thread(user_name, api_no, param) return result, info def add_body_param(self, user_name, api_no, param, necessary, type, desc, role): if role & self.role_value["api_new"] <= 0: return False, u"您没有权限" result, info = self.api_help.new_api_body(api_no, {param: {"necessary": necessary, "type": type, "desc": desc}}) if result is True: self._send_api_update_message_thread(user_name, api_no, param) return result, info def add_input_example(self, user_name, api_no, example, desc, role): if role & self.role_value["api_new"] <= 0: return False, u"您没有权限" result, info = self.api_help.new_api_input(api_no, [{"desc": desc, "example": example}]) if result is True: self._send_api_update_message_thread(user_name, api_no, u"请求示例") return result, info def add_output_example(self, user_name, api_no, example, desc, role): if role & self.role_value["api_new"] <= 0: return False, u"您没有权限" result, info = self.api_help.new_api_output(api_no, [{"desc": desc, "example": example}]) if result is True: self._send_api_update_message_thread(user_name, api_no, u"返回示例") return result, info def add_care(self, api_no, user_name, role): if role & 8 <= 0: return False, u"您没有权限" return self.api_help.new_api_care(api_no, user_name) def add_module_care(self, user_name, role, module_no): if role & 8 <= 0: return False, u"您没有权限" return self.api_help.new_module_care(module_no, user_name) def get_api_list(self, module_no, role): if role & self.role_value["api_look"] <= 0: return False, u"您没有权限" result, api_list = self.api_help.get_api_list(module_no) if result is True and role & self.role_value["api_new"] <= 0: len_api = len(api_list["api_list"]) for i in range(len_api - 1, -1, -1): api_item = api_list["api_list"][i] if api_item["stage"] == u'新建': api_list["api_list"].remove(api_item) return result, api_list def delete_header(self, role, api_no, param): if role & self.role_value["api_new"] <= 0: return False, u"您没有权限" return self.api_help.del_api_header(api_no, param) def delete_predefine_param(self, role, api_no, param): if role & self.role_value["api_new"] <= 0: return False, u"您没有权限" return self.api_help.del_predefine_param(api_no, param) def delete_body(self, role, api_no, param): if role & self.role_value["api_new"] <= 0: return False, u"您没有权限" return self.api_help.del_api_body(api_no=api_no, param=param) def delete_input(self, input_no, role): if role & self.role_value["api_new"] <= 0: return False, u"您没有权限" return self.api_help.del_api_input(input_no) def delete_ouput(self, output_no, role): if role & self.role_value["api_new"] <= 0: return False, u"您没有权限" return self.api_help.del_api_output(output_no) def delete_care(self, api_no, user_name): return self.api_help.del_api_care(api_no, user_name) def delete_module_care(self, user_name, module_no): return self.api_help.del_module_care(module_no, user_name) def delete_api(self, api_no, user_name): return self.api_help.del_api_info(api_no, user_name) def set_api_status(self, user_name, role, api_no, stage): if role & self.role_value["api_new"] <= 0: return False, u"您没有权限" if stage == 2: # 必须至少一个返回示例 output_info = self.api_help.get_api_output(api_no) if len(output_info) <= 0: return False, u"请至少提交一个返回示例" result, info = self.api_help.set_api_stage(api_no, stage) return result, info # 针对API状态码的应用 def get_fun_info(self, role): if role & self.role_value["status_code_look"] <= 0: return False, u"您没有权限" return self.api_status.get_function_info() def get_status(self, role, *args, **kwargs): if role & self.role_value["status_code_look"] <= 0: return False, u"您没有权限" return self.api_status.get_status_code(*args, **kwargs) def get_error_type(self, role): if role & self.role_value["status_code_look"] <= 0: return False, u"您没有权限" return self.api_status.get_error_type() def new_service_module(self, user_name, role, service_title, service_desc): if role & self.role_value["status_code_module"] <= 0: return False, u"您没有权限" result, info = self.api_status.insert_service_module(service_title, service_desc) if result is False: return result, info service_id = info["service_id"] r, data = self.api_status.insert_function_module(service_id, u"公共功能模块", u"本服务模块所有功能模块可公共使用的错误状态码") if r is True: function_id = data["function_id"] error_info = [{"type_id": 0, "error_desc": u"访问系统正常,待用"}, {"type_id": 0, "error_desc": u"访问系统正常,将返回数据"}, {"type_id": 0, "error_desc": u"访问系统正常,仅返回成功信息"}, {"type_id": 0, "error_desc": u"访问系统正常,返回警告信息"}, {"type_id": 99, "error_desc": u"未经处理的异常,模块统一处理返回内部错误"}] r, data = self.api_status.new_mul_status_code(int(service_id), int(function_id), error_info, user_name) return result, info def new_function_module(self, user_name, role, service_id, function_title, function_desc): if role & self.role_value["status_code_module"] <= 0: return False, u"您没有权限" return self.api_status.insert_function_module(service_id, function_title, function_desc) def new_api_status(self, user_name, role, service_id, fun_id, type_id, error_id, error_desc): if role & self.role_value["status_code_new"] <= 0: return False, u"您没有权限" return self.api_status.new_status_code(service_id, fun_id, type_id, error_id, error_desc, user_name) def new_mul_api_status(self, user_name, role, service_id, fun_id, error_info): if role & self.role_value["status_code_new"] <= 0: return False, u"您没有权限" return self.api_status.new_mul_status_code(service_id, fun_id, error_info, user_name) def delete_api_status(self, user_name, role, status_code): if role & self.role_value["status_code_del"] < self.role_value["status_code_del"]: return False, u"您没有权限" return self.api_status.del_status_code(status_code) # 针对BUG的应用 def get_bug_list(self, role): if role & self.role_value["bug_look"] <= 0: return False, u"您没有权限" return self.bug.get_bug_list() def get_bug_statistic(self, role): if role & self.role_value["bug_look"] <= 0: return False, u"您没有权限" return self.bug.get_statistic() def get_bug_info(self, role, bug_no): if role & self.role_value["bug_look"] <= 0: return False, u"您没有权限" return self.bug.get_bug_info(bug_no) def new_bug(self, user_name, role, bug_title): if role & self.role_value["bug_new"] <= 0: return False, u"您没有权限" return self.bug.new_bug_info(bug_title, user_name) def add_bug_str_example(self, user_name, role, bug_no, content): if role & self.role_value["bug_new"] <= 0: return False, u"您没有权限" # 判断该bug是否是user_name提交的 select_sql = "SELECT submitter,bug_status FROM %s WHERE bug_no='%s';" % (self.bug.bug, bug_no) result = self.db.execute(select_sql) if result == 0: return False, u"BUG 不存在" submitter, bug_status = self.db.fetchone() if submitter != user_name: return False, u"您不能修改别人的BUG" if bug_status > 2: return False, u"BUG 已不能修改" return self.bug.new_bug_example(bug_no, 1, content) def add_bug_img_example(self, user_name, role, bug_no, path): if role & self.role_value["bug_new"] <= 0: return False, u"您没有权限" # 判断该bug是否是user_name提交的 select_sql = "SELECT submitter,bug_status FROM %s WHERE bug_no='%s';" % (self.bug.bug, bug_no) result = self.db.execute(select_sql) if result == 0: return False, u"BUG 不存在" submitter, bug_status = self.db.fetchone() if submitter != user_name: return False, u"您不能修改别人的BUG" if bug_status > 2: return False, u"BUG 已不能修改" return self.bug.new_bug_example(bug_no, 2, path) def _wx_send_bug(self, bug_no, user_name, type, link_desc): select_sql = "SELECT nick_name,wx_id,bug_title FROM %s as u,%s as b, %s as o " \ "WHERE u.user_name=o.user_name AND o.bug_no=b.bug_no " \ "AND type=%s AND u.user_name='%s' AND o.bug_no='%s';" \ % (self.user.user, self.bug.bug, self.bug.bug_owner, type, user_name, bug_no) result= self.db.execute(select_sql) if result != 0: nick_name, wx_id, bug_title = self.db.fetchone() if wx_id is not None: bug_url = "http://gene.ac/dev/bug/info?bug_no=%s" % bug_no title = u"%s, 您被标记为BUG %s" % (nick_name, link_desc) remark = u"请查看%s,如果是你的BUG,请尽快修复。" % bug_url pass def _wx_send_bug_thread(self, bug_no, user_name, type, link_desc): t = Thread(target=self._wx_send_bug, args=(bug_no, user_name, type, link_desc)) t.start() def add_bug_link(self, bug_no, user_name, role, link_user, link_type): if role & self.role_value["bug_new"] <= 0: return False, u"您没有权限" # 判断当前bug是否允许添加关联者 select_sql = "SELECT submitter,bug_status FROM %s WHERE bug_no='%s';" % (self.bug.bug, bug_no) result = self.db.execute(select_sql) if result == 0: return False, u"BUG 不存在" submitter, bug_status = self.db.fetchone() if bug_status > 2: return False, u"BUG 已不能修改" # 判断被链接者是否可以被链接 select_sql = "SELECT role FROM %s WHERE user_name='%s';" % (self.sys_user, link_user) result = self.db.execute(select_sql) if result == 0: return False, u"添加关联账户不存在" link_role = self.db.fetchone()[0] if link_role & self.role_value["bug_link"] <= 0: return False, u"添加关联账户无效" if link_type == "ys": if bug_status > 1: return False, u"BUG 状态已不允许添加疑似拥有者" return self._add_ys_link(bug_no, user_name, link_user) elif link_type == "owner": return self._add_owner_link(bug_no, user_name, link_user, submitter) elif link_type == "fix": return self._add_fix_link(bug_no, user_name, link_user, submitter) elif link_type == "cancel": return self._add_channel_link(bug_no, user_name, role, link_user, submitter) elif link_type == "design": return self._add_design_link(bug_no, user_name, role, link_user) else: return False, u"错误的请求" def delete_bug_link(self, bug_no, user_name, role, link_user, link_type): if role & self.role_value["bug_new"] <= 0: return False, u"您没有权限" # 判断当前bug是否允许删除关联者 select_sql = "SELECT submitter,bug_status FROM %s WHERE bug_no='%s';" % (self.bug.bug, bug_no) result = self.db.execute(select_sql) if result == 0: return False, u"BUG 不存在" submitter, bug_status = self.db.fetchone() if bug_status > 2: return False, u"BUG 已不能修改" if link_type == "ys": if bug_status > 1: return False, u"BUG 状态已不允许修改疑似拥有者" link_type_num = 1 elif link_type == "owner": link_type_num = 2 else: return False, u"错误的请求" # 仅当当前关联者超过一个时才可以删除 其他 select_sql = "SELECT user_name,adder FROM %s WHERE bug_no='%s' AND type=%s;" \ % (self.bug.bug_owner, bug_no, link_type_num) result = self.db.execute(select_sql) if result <= 1: return False, u"仅当关联者超过1个以后,才能删除" for item in self.db.fetchall(): if item[0] == link_user and item[1] == user_name: return self.bug.del_bug_link(bug_no, link_user, link_type_num, user_name) return False, u"您无权限删除" def _add_ys_link(self, bug_no, user_name, link_user): # 有new bug的权限均可添加疑似bug拥有者 result, info = self.bug.new_bug_link(bug_no, link_user, 1, user_name) if result is True: # 发送微信消息 pass return result, info def _add_owner_link(self, bug_no, user_name, link_user, submitter): # 判断操作者是否有权限操作 操作者可以是关联自己 或者 是bug的提交者 if user_name != link_user: # 判断提交者是否是bug提交者 if submitter != user_name: return False, u"您不能修改别人的BUG" result, info = self.bug.new_bug_link(bug_no, link_user, 2, user_name) if result is True: # 发送微信消息 pass return result, info def _add_fix_link(self, bug_no, user_name, link_user, submitter): # 只有BUG提交者可以标记为修复 if submitter != user_name: return False, u"您不能修改别人的BUG的状态" return self.bug.new_bug_link(bug_no, link_user, 3, user_name) def _add_channel_link(self, bug_no, user_name, role, link_user, submitter): # 只有bug提交者才 或者拥有bug_channel 权限的人可以操作 if submitter != user_name and role & self.role_value["bug_cancel"]: return False, u"您无权限修改该BUG的状态" return self.bug.new_bug_link(bug_no, link_user, 4, user_name) def _add_design_link(self, bug_no, user_name, role, link_user): # 拥有bug_channel 权限的人可以操作 if role & self.role_value["bug_cancel"]: return False, u"您无权限修改该BUG的状态" return self.bug.new_bug_link(bug_no, link_user, 5, user_name) # 发送API更新提醒 def _send_module_message(self, user_name, module_no, api_no, title, method, desc): care_info = self.api_help.get_module_care_list(module_no=module_no) rec_user = [] rec_email = [] for care_user in care_info: if care_user["email"] is None: continue rec_user.append("%s|%s" % (care_user["user_name"], care_user["email"])) rec_email.append(care_user["email"]) email_content_lines = [] email_content_lines.append(u"模块增加新的API") email_content_lines.append(u"API标题:%s" % title) email_content_lines.append(u"API访问方法:%s" % method) email_content_lines.append(u"API描述:%s" % desc) access_url = "http://dms.gene.ac/dev/api/info/?api_no=%s" % api_no email_content_lines.append(u"<a href='%s'>查看详情</a>" % access_url) email_content = "<br/>".join(email_content_lines) # 写入更新信息 self.api_help.new_send_message(user_name, rec_user, email_content) for email in rec_email: my_email.send_mail(email, u"模块增加新的API:%s" % title, email_content) def _send_api_update_message(self, user_name, api_no, param): result, api_info = self.api_help.get_api_basic_info(api_no) if result is False: return False # 判断添加api是否已完成 if api_info["stage"] != 2: return False care_info = self.api_help.get_api_care_info(api_no) rec_user = [] rec_email = [] for care_user in care_info: if care_user["email"] is None: continue rec_user.append("%s|%s" % (care_user["user_name"], care_user["email"])) rec_email.append(care_user["email"]) email_content_lines = [] email_content_lines.append(u"API更新了参数") email_content_lines.append(u"API标题:%s" % api_info["api_title"]) email_content_lines.append(u"API描述:%s" % api_info["api_desc"]) email_content_lines.append(u"更新的参数名称:%s" % param) access_url = "http://dms.gene.ac/dev/api/info/?api_no=%s" % api_no email_content_lines.append(u"<a href='%s'>查看详情</a>" % access_url) email_content = "<br/>".join(email_content_lines) # 写入更新信息 self.api_help.new_send_message(user_name, rec_user, email_content) for email in rec_email: my_email.send_mail(email, u"API:%s,更新了参数" % api_info["api_title"], email_content) return True def _send_api_update_message_thread(self, user_name, api_no, param): t = Thread(target=self._send_api_update_message, args=(user_name, api_no, param)) t.start() def _send_api_completed_message(self, user_name, api_no): result, api_info = self.api_help.get_api_basic_info(api_no) if result is False: return False care_info = self.api_help.get_api_care_info(api_no) rec_user = [] rec_email = [] for care_user in care_info: if care_user["email"] is None: continue rec_user.append("%s|%s" % (care_user["user_name"], care_user["email"])) rec_email.append(care_user["email"]) email_content_lines = [] email_content_lines.append(u"API文档完成") email_content_lines.append(u"API标题:%s" % api_info["api_title"]) email_content_lines.append(u"API描述:%s" % api_info["api_desc"]) access_url = "http://dms.gene.ac/dev/api/info/?api_no=%s" % api_no email_content_lines.append(u"<a href='%s'>查看详情</a>" % access_url) email_content = "<br/>".join(email_content_lines) # 写入更新信息 self.api_help.new_send_message(user_name, rec_user, email_content) for email in rec_email: my_email.send_mail(email, u"API:%s,文档已完成" % api_info["api_title"], email_content) return True def _send_api_completed_message_thread(self, user_name, api_no): t = Thread(target=self._send_api_completed_message, args=(user_name, api_no)) t.start() def test_send(self, user_name, content): result, user_info = self.user.get_user_info(user_name) if result is False: return False, "user exception" if user_info["email"] is None: return False, "user not config email" my_email.send_mail_thread(user_info["email"], u"晶云文档系统测试发送与接收邮件", content) return True, user_info["email"] # 针对查看晶云平台运行日志 def look_jy_log(self, user_name, role, start_time=None, end_time=None, level=None, search_url=None, search_account=None): if role & self.role_value["log_look"] <= 0: return False, u"您没有权限" result, info = self.jy_log.show_log(start_time=start_time, end_time=end_time, level=level, search_url=search_url, search_account=search_account) return result, info def new_login_server(self, server_ip, server_name, user_ip, user_name, login_time): return self.jy_log.insert_login_server(server_ip, server_name, user_ip, user_name, login_time) def get_login_info(self): return self.jy_log.select_login_log() def register_log_task(self): return self.jy_log.register_daily_task() def get_daily_log(self): return self.jy_log.select_daily_log() def get_one_log(self, user_name, role, log_no): if role & self.role_value["log_query"] <= 0: return False, "您没有权限" result, info = self.jy_log.select_log(log_no) return result, info def send_daily_log(self, template_html): result, user_list = self.user.get_role_user(self.role_value["log_receive"]) subject = u"%s运行日志" % datetime.now().strftime(DATE_FORMAT_STR) if result is True: for u in user_list: my_email.send_mail(u["email"], subject, template_html) def register_login_task(self): return self.jy_log.register_login_task() # 针对工具 def get_ip_info(self, ip_value): return self.ip.select_info_info(ip_value) # 针对发布 def get_task(self, user_name, user_role): if user_role & self.role_value["release_ih_N"] <= 0: return False, u"您没有权限" return self.release_man.select_release_task() def new_task(self, user_name, user_role, reason, restart_service, reason_desc): if user_role & self.role_value["release_ih_N"] <= 0 and user_name != "system": return False, u"您没有权限" if user_role & self.role_value["release_ih_V"] <= 0 and user_name != "system" and restart_service == 0: return False, u"您没有权限" if restart_service == 0: result, web_pull_requests = self.release_man.select_web_pull_request() if len(web_pull_requests) <= 0: return False, u"WEB无更新不可提交" result, api_pull_requests = self.release_man.select_api_pull_request() if len(api_pull_requests) <= 0: return False, u"API无更新不可提交" elif restart_service == 1: result, api_pull_requests = self.release_man.select_api_pull_request() if len(api_pull_requests) <= 0: return False, u"API无更新不可提交" elif restart_service == 2: result, web_pull_requests = self.release_man.select_web_pull_request() if len(web_pull_requests) <= 0: return False, u"WEB无更新不可提交" result, info = self.release_man.select_release_task(user_name=user_name) if result is False: return False, info elif len(info) >= 2: return False, u"今日已不再允许预约" return self.release_man.new_release_task(user_name, reason, restart_service, reason_desc) def update_task(self, release_no, run_result): return self.release_man.update_release_task(release_no, run_result) def release_ih(self): return self.release_man.release_ih() # 针对公共参数格式 def add_param_format(self, user_name, user_role, param, param_type, **kwargs): return self.param_man.new_param_format(user_name, param, param_type, **kwargs) def update_param_format(self, user_name, user_role, param, **kwargs): return self.param_man.update_param_format(user_name, param, **kwargs) def get_params_info(self, user_name, user_role): return self.param_man.select_param_format() # 针对pull request def add_pull_request(self, **kwargs): return self.pull_request_man.add_pull_request(**kwargs)
coefs = np.round(coefs, 2) print("Explanation: ") for i in range(coefs.shape[0]): print(i - 1, coefs[i]) print("") def mod(x, i, d): x_new = np.copy(x) x_new[i] += d return x_new # Load the data np.random.seed(seed) # Get the same data everytime data = DataManager("../Datasets/housing.csv") X_train = data.X_train n_input = X_train.shape[1] # Load the network shape with open("../UCI-None/config.json", "r") as f: config_list = json.load(f) config = config_list["housing"] shape = [n_input] for i in range(config[0]): shape.append(config[1]) shape.append(1)
def getImgData(self): data = DataManager.getImage(self.path, self.imageNum) return data.tolist() # Convert to list to work around numpy bug
def __init__(self, dataPath, labelPath): self.stop = False dataPath = 'Data/Test Set Images/' + dataPath + '.gz' labelPath = 'Data/Test Set Labels/' + labelPath + '.gz' self.window = Tk.Toplevel() self.window.title('Testing') self.window.config(bg=colourScheme['background']) # window.overrideredirect(1) self.window.wm_geometry('400x120') self.window.resizable(False, False) self.window.grid_rowconfigure(0, weight=1) self.window.grid_columnconfigure(1, weight=1) self.window.grab_set() sets = DataManager.getSetSize(dataPath) # Setup TreeView/Table self.table = ttk.Treeview(self.window) self.table['columns'] = ('Instances', 'Correct', 'Accuracy') self.table.column('#0', minwidth=30, stretch=Tk.NO) self.table.column('Instances', minwidth=60, stretch=Tk.NO) self.table.column('Correct', minwidth=120, stretch=Tk.NO) self.table.column('Accuracy', minwidth=60, stretch=Tk.NO) self.table.heading('#0', text='Digit', anchor=Tk.W) self.table.heading('Instances', text='Instances', anchor=Tk.W) self.table.heading('Correct', text='Correct Categorisaion', anchor=Tk.W) self.table.heading('Accuracy', text='Accuracy', anchor=Tk.W) # Setup Progressbar self.progressLabel = Tk.Label(self.window, bg=colourScheme['background'], text='Progress:') self.progressLabel.grid(row=0, column=0, sticky='sw', padx=20, pady=(10, 0)) self.progressBar = ttk.Progressbar(self.window, orient='horizontal', maximum=sets, mode='determinate') self.progressBar.grid( row=1, column=0, columnspan=2, sticky='we', padx=10, pady=10, ) # Buttons btnFrame = Tk.Frame(self.window, bg=colourScheme['background']) btnFrame.grid(row=2, column=1, sticky='e', padx=10, pady=(0, 10)) self.closeBtn = Tk.Button(btnFrame, text='Close', state='disabled', command=lambda : \ self.closeFunc()) self.stopBtn = Tk.Button(btnFrame, text='Stop', command=lambda : self.stopFunc()) self.stopBtn.grid(row=0, column=0, sticky='w') self.closeBtn.grid(row=0, column=1, padx=(10, 0), sticky='e') # Check if there is a network to test if Globals.NN.structure == []: self.progressLabel['text'] = 'Progress: Network Missing' self.progressBar['value'] = sets self.stopFunc() return # Run Testing and display grid Globals.NN.test(dataPath, labelPath, self) self.stopFunc() self.progressLabel.destroy() self.progressBar.destroy() self.table.grid( row=0, column=0, columnspan=2, sticky='nswe', padx=10, pady=10, ) self.window.wm_geometry('700x350') return
num_features=num_features, num_samples=num_samples) coef_pairs = exp.local_exp[1] for pair in coef_pairs: coefs[pair[0]] = pair[1] coefs = coefs / sd intercept = exp.intercept[1] - np.sum(coefs * u) return np.insert(coefs, 0, intercept) # Load the data data = DataManager("../Datasets/" + name + ".csv") X_train = data.X_train n_input = X_train.shape[1] # Load the network shape with open("../UCI-None/config.json", "r") as f: config_list = json.load(f) config = config_list[name] shape = [n_input] for i in range(config[0]): shape.append(config[1]) shape.append(1)
def run(): # Get Configs config = configparser.ConfigParser() config.read('config.ini') colourScheme = config['colourScheme'] neuralNet = config['neuralNet'] maxLayers = list(range(2, int(neuralNet['maxLayers']) + 1)) defaultData = config['defaults']['dataSets'].split(',\n') # Setup Layout Root = Tk.Tk() Root.title('Neural Network Experiment') Root.configure(bg=colourScheme['background']) Root.minsize(1300, 800) Root.geometry('1300x800+0+0') Root.grid_columnconfigure(1, weight=1) Root.grid_rowconfigure(0, weight=1) # Left Pane =============================================== LeftPane = Tk.Frame(Root, width=600, height=800, bg=colourScheme['background']) LeftPane.grid(row=0, column=0, padx=(20, 10), pady=20, sticky='ns') # Get Network Display Canvas Ready RightPane = Tk.Frame(Root, bg=colourScheme['background']) VisRepFrame = Tk.Frame(RightPane) VisRepFrame.grid_columnconfigure(0, weight=1) VisRepFrame.grid(row=2, columnspan=2, pady=10, sticky='nwe') VisRep = Tk.Canvas(VisRepFrame, bg=colourScheme['nodeBkGd'], cursor='hand2') VisRep.grid(row=0, column=0, sticky='we') VisRepHbar = Tk.Scrollbar(VisRepFrame, orient='horizontal', command=VisRep.xview) VisRepHbar.grid(row=1, column=0, columnspan=2, sticky='nswe') VisRepVbar = Tk.Scrollbar(VisRepFrame, orient='vertical', command=VisRep.yview) VisRepVbar.grid(row=0, column=1, sticky='nswe') VisRep.config(xscrollcommand=VisRepHbar.set, yscrollcommand=VisRepVbar.set, scrollregion=VisRep.bbox('all')) # Import the default network importModel(defaultData[4], VisRep) # Network construction pane defaultParams = [ int(neuralNet['maxNeurons']), float(neuralNet['learningRate']), neuralNet['activationFunc'], neuralNet['errorFunc'] ] layerSetup = leftPaneLayers(LeftPane, colourScheme, defaultParams, VisRep) NoOfLayers_Label = Tk.Label(LeftPane, bg=colourScheme['background'], text='Number of Layers:') NoOfLayers_Label.grid(row=0, column=0, columnspan=2, sticky='w') NoOfLayers_Menu = ttk.Combobox(LeftPane, state='readonly', values=maxLayers) NoOfLayers_Menu.set(2) NoOfLayers_Menu.grid(row=1, column=0, columnspan=2, sticky='we') NoOfLayers_Menu.bind('<<ComboboxSelected>>', lambda x: \ [layerSetup.renderLeftLayers(int(NoOfLayers_Menu.get())), LeftPane.focus()]) NumberOfNeurons_Label = Tk.Label(LeftPane, bg=colourScheme['background'], text='Number of Neurons:') NumberOfNeurons_Label.grid(row=2, column=1, sticky='w', pady=(20, 0)) layerSetup.renderLeftLayers() # RightPane =============================================== RightPane.grid_columnconfigure(1, weight=1) RightPane.grid_rowconfigure(15, weight=1) RightPane.grid(row=0, column=1, padx=(0, 20), pady=20, sticky='nswe') Node.drawNodes(VisRep) VisRep.bind('<Button-1>', lambda x: Node.click(VisRep)) # Result Graphs (Canvas is scrollable) -------------------- ResultFrame = Tk.Frame(RightPane, bg='white') ResultFrame.grid_columnconfigure(0, weight=1) ResultFrame.grid_rowconfigure(0, weight=1) ResultFrame.grid( row=2, column=2, rowspan=14, padx=(10, 0), pady=(10, 0), sticky='nswe', ) ResultScrollable = Tk.Canvas(ResultFrame) InternalScrollableFrame = Tk.Frame(ResultScrollable) ResultScrollable.create_window(0, 0, window=InternalScrollableFrame, anchor='nw') ResultScrollable.grid(row=0, column=0, padx=(5, 0), sticky='nswe') graphCollection = [] for i in range(10): graphCollection.append(Graph(InternalScrollableFrame, i)) ResultFrameVbar = Tk.Scrollbar(ResultFrame, orient='vertical', command=ResultScrollable.yview) ResultFrameVbar.grid(row=0, column=1, sticky='nswe') ResultScrollable.config(yscrollcommand=ResultFrameVbar.set, scrollregion=ResultScrollable.bbox('all')) # AttackFrame --------------------------------------------- AtkFrame = Tk.Frame(RightPane, bg=colourScheme['background']) AtkFrame.grid_columnconfigure(0, weight=1, minsize=235) AtkFrame.grid(row=3, column=1, rowspan=13, padx=(10, 0), sticky='nswe') # Create and show image ImgCanv = ImageDisplay.image( AtkFrame, 'Data/Attack Set Images/' + defaultData[5] + '.gz') ImgCanv.renderImage() # Buttons ImgBtnFrame = Tk.Frame(AtkFrame) PrevImageBtn = Tk.Button(ImgBtnFrame, text='<', width=3, command=ImgCanv.prevImage) PerturbBtn = Tk.Button( ImgBtnFrame, text='Perturb', width=23, command=lambda: perturbingWindow(ImgCanv, graphCollection)) NextImageBtn = Tk.Button(ImgBtnFrame, text='>', width=3, command=ImgCanv.nextImage) ImgBtnFrame.grid(row=1, column=0, pady=10) PrevImageBtn.grid(row=0, column=0) PerturbBtn.grid(row=0, column=1) NextImageBtn.grid(row=0, column=2) PerturbAllBtn = Tk.Button(ImgBtnFrame, text='Perturb All Pixels', command=lambda : \ perturbingWindow(ImgCanv, graphCollection, findMax=True)) PerturbAllBtn.grid(row=1, column=0, columnspan=3, sticky='we') PlotHeatBtn = Tk.Button( ImgBtnFrame, text='Plot Heatmaps', command=lambda: perturbingWindow( ImgCanv, graphCollection, findMax=True, plotHeat=True)) PlotHeatBtn.grid(row=2, column=0, columnspan=3, sticky='we') # Perturb data Comboboxes AtkPickerFrame = Tk.Frame(AtkFrame, bg=colourScheme['background']) AtkPickerFrame.grid(column=1, row=0, columnspan=4, padx=10, sticky='nw') AtkImageLabel = Tk.Label(AtkPickerFrame, bg=colourScheme['background'], text='Images to be Perturbed: ') AtkImageCombo = ttk.Combobox( AtkPickerFrame, width=25, state='readonly', values=DataManager.getDataName('attack images')) AtkImageCombo.bind('<<ComboboxSelected>>', lambda x: \ RightPane.focus()) AtkImageCombo.set(defaultData[5]) AtkImageLabel.grid(column=1, row=0, sticky='w') AtkImageCombo.grid(column=1, row=1, sticky='w') ImportAtkSetBtn = Tk.Button(AtkPickerFrame, text='Import Attack Images', command=lambda : \ importAttackSet(AtkImageCombo.get(), ImgCanv)) ImportAtkSetBtn.grid(column=1, row=4, pady=(10, 0), sticky='we') # Data Pickers -------------------------------------------- TrainImageLabel = Tk.Label(RightPane, bg=colourScheme['background'], text='Training Images:') TrainImageCombo = ttk.Combobox( RightPane, width=25, state='readonly', values=DataManager.getDataName('train images')) TrainImageCombo.bind('<<ComboboxSelected>>', lambda x: \ RightPane.focus()) TrainImageCombo.set(defaultData[0]) TrainImageLabel.grid(column=0, row=3, sticky='w') TrainImageCombo.grid(column=0, row=4, sticky='w') TrainLabelsLabel = Tk.Label(RightPane, bg=colourScheme['background'], text='Training Labels:') TrainLabelsCombo = ttk.Combobox( RightPane, width=25, state='readonly', values=DataManager.getDataName('train labels')) TrainLabelsCombo.bind('<<ComboboxSelected>>', lambda x: \ RightPane.focus()) TrainLabelsCombo.set(defaultData[1]) TrainLabelsLabel.grid(column=0, row=5, sticky='w') TrainLabelsCombo.grid(column=0, row=6, sticky='w') TestImageLabel = Tk.Label(RightPane, bg=colourScheme['background'], text='Test Images:') TestImageCombo = ttk.Combobox( RightPane, width=25, state='readonly', values=DataManager.getDataName('test images')) TestImageCombo.bind('<<ComboboxSelected>>', lambda x: \ RightPane.focus()) TestImageCombo.set(defaultData[2]) TestImageLabel.grid(column=0, row=7, sticky='w') TestImageCombo.grid(column=0, row=8, sticky='w') TestLabelsLabel = Tk.Label(RightPane, bg=colourScheme['background'], text='Test Labels:') TestLabelsCombo = ttk.Combobox( RightPane, width=25, state='readonly', values=DataManager.getDataName('test labels')) TestLabelsCombo.bind('<<ComboboxSelected>>', lambda x: \ RightPane.focus()) TestLabelsCombo.set(defaultData[3]) TestLabelsLabel.grid(column=0, row=9, sticky='w') TestLabelsCombo.grid(column=0, row=10, sticky='w') # Buttons ----------------------------------------------------- opBtnFrame = Tk.Frame(RightPane, bg=colourScheme['background']) opBtnFrame.grid_columnconfigure(0, weight=1) opBtnFrame.grid_columnconfigure(1, weight=1) opBtnFrame.grid(row=11, pady=(10, 0), sticky='we') TrainBtn = Tk.Button(opBtnFrame, text='Train', command=lambda : \ trainingWindow(TrainImageCombo.get(), TrainLabelsCombo.get())) TrainBtn.grid(row=0, column=0, sticky='we') TestBtn = Tk.Button(opBtnFrame, text='Test', command=lambda : \ testingWindow(TestImageCombo.get(), TestLabelsCombo.get())) TestBtn.grid(row=0, column=1, padx=(5, 0), sticky='we') ExportBtn = Tk.Button(opBtnFrame, text='Export Model', command=lambda: exportFunc()) ExportBtn.grid(row=1, column=0, columnspan=3, pady=(5, 0), sticky='we') # Import Model ------------------------------------------------- ImportLabel = Tk.Label(RightPane, bg=colourScheme['background'], text='Pretrained Model:') ImportLabel.grid(column=0, row=12, pady=(10, 0), sticky='w') ImportCombo = ttk.Combobox(RightPane, width=25, state='readonly', values=ModelManager.getModelNames(), postcommand=lambda : \ updateImportCombo(ImportCombo)) ImportCombo.bind('<<ComboboxSelected>>', lambda x: \ RightPane.focus()) ImportCombo.set(defaultData[4]) ImportCombo.grid(column=0, row=13, sticky='w') ImportBtn = Tk.Button(RightPane, text='Import Model', command=lambda : \ importModel(ImportCombo.get(), VisRep)) ImportBtn.grid(column=0, row=14, pady=(10, 0), sticky='we') # ============================================================= Tk.mainloop()
def __init__(self, dataPath, labelPath): self.stop = False dataPath = 'Data/Train Set Images/' + dataPath + '.gz' labelPath = 'Data/Train Set Labels/' + labelPath + '.gz' self.window = Tk.Toplevel() self.window.title('Training') self.window.config(bg=colourScheme['background']) # window.overrideredirect(1) self.window.wm_geometry('400x120') self.window.resizable(False, False) self.window.grid_rowconfigure(0, weight=1) self.window.grid_columnconfigure(1, weight=1) self.window.grab_set() sets = DataManager.getSetSize(dataPath) self.progressLabel = Tk.Label(self.window, bg=colourScheme['background'], text='Progress:') self.progressLabel.grid(row=0, column=0, sticky='sw', padx=20, pady=(10, 0)) self.progressBar = ttk.Progressbar(self.window, orient='horizontal', maximum=sets, mode='determinate') self.progressBar.grid( row=1, column=0, columnspan=2, sticky='we', padx=10, pady=10, ) # Buttons btnFrame = Tk.Frame(self.window, bg=colourScheme['background']) btnFrame.grid(row=2, column=1, sticky='e', padx=10, pady=(0, 10)) self.closeBtn = Tk.Button(btnFrame, text='Close', state='disabled', command=lambda : \ self.closeFunc()) self.stopBtn = Tk.Button(btnFrame, text='Stop', command=lambda: self.stopFunc()) self.stopBtn.grid(row=0, column=0, sticky='w') self.closeBtn.grid(row=0, column=1, padx=(10, 0), sticky='e') # Call Network.train() if Globals.NN.structure == []: self.progressLabel['text'] = 'Progress: Network Missing' self.trainingProgress['value'] = sets self.stopFunc() return # Run Training Globals.NN.train(dataPath, labelPath, self) self.stopFunc() return
#%% import warnings import pandas as pd from sklearn import preprocessing from Data import DataManager from Analyser import Analyser pd.set_option('display.max_rows', 100) pd.set_option('display.max_columns', 51) output = 'output/' size = (150, 100) warnings.filterwarnings('ignore') # %% # 1. Read from Dataset dataManager = DataManager() dfFullData = dataManager.readData() #%% # 2. Analysing Data from Dataset dfFullData.describe() #%% dfFullData.info() #%% # Base on displot 01_INITIAL_DistPlot.png, boxplot 02_OUTLIER_BoxPlot.png, data information above and the original datset: # 1.some feature in dataset does not have normal distibution thus has to be skewed, # 2.The true label, 'diagnosis' has binary values and the ratio of Yes to No is disproportionate thus stratification has to be done. # 3.The range of numercal values in some features is wide thus has to be scaled down. # 4.The true label, 'diagnosis' has to be converted to numbers via label encoding since it has only 2 values # 5.There are some features with outliers, thus outliers has to be removed # 6.Features 'ID' and 'Unnamed' has to be dropped as they are not useful # 7. There are no empty cells # In addition, the follwing steps also has to be checked:
def train( self, data, expecteds, window, normalise=False, ): # Get image size, and num of images from data imgCount = DataManager.getSetSize(data) imgSize = DataManager.getImgSize(data) # Get label file ready expecteds = gzip.open(expecteds, 'r') expecteds.read(8) # get past headers # Get images and train data = gzip.open(data, 'r') for i in range(0, imgCount): # print('Training on Image: ', i+1) # Build image array buffer = data.read(imgSize) image = np.frombuffer(buffer, dtype=np.uint8) # One hot encode label label = int.from_bytes(expecteds.read(1), byteorder='big') expectedOutput = np.zeros(10) expectedOutput[label] = 1 # Update progress bar window.progressBar['value'] += 1 window.window.update() # Do passes self.forwardProp(image, normalise=normalise) self.backwardProp(expectedOutput) # Check if training should be stopped if window.stop == True: break # Setup window things window.progressLabel['text'] = 'Progress: Complete!' # Free resources data.close() expecteds.close() return