def __init__( self, appiconset_path="/Users/heyongchao/gitclone/xx/Assets.xcassets/AppIcon.appiconset" ): self.default_image_path = '%s/images/kw_logo_mark_version.png' % gl.get_value( "dirname") self.AppIcon_base_path = appiconset_path
def handle_icon_images(self): # jsonpath = os.getcwd() + "/Contents.json" # 目录是否存在,不存在则cp一份过去 # mkdirlambda = lambda x: os.system("cp -r resource/* " + x) if not os.path.exists(x) else True # mkdirlambda(self.AppIcon_base_path) # 先强制拷贝进去,以我的为准吧 os.system("cp -rf %s/resource/AppIcon.appiconset/* %s" % (gl.get_value("dirname"), self.AppIcon_base_path)) jsonpath = self.AppIcon_base_path + "/Contents.json" if not os.path.exists(jsonpath): print("Contents.json path not exit") return with open(jsonpath, 'r') as f: jsonstr = f.read() modle = json.loads(jsonstr) arrs = modle['images'] print(arrs) icon_models = [] for obj in arrs: size = obj["size"] idiom = obj["idiom"] scale = obj["scale"] # 下面的处理其实有问题,还是需要改json filename = "Icon-%s-%s-%s.png" % ( idiom, size, scale) if 'filename' not in obj else obj["filename"] icom = iconImg(size=size, idiom=idiom, filename=filename, scale=scale) # icon_models.append(icom) self.createImg(icom) print("all make success")
def KSE(weight_kse, G=None, T=None): weight = weight_kse.cuda().detach() cin = weight.shape[1] cout = weight.shape[0] weight = weight.transpose(1, 0).reshape(cin, cout, -1) weight_temp = weight.cpu() ks_weight = np.sum(np.linalg.norm(weight_temp, ord=1, axis=2), 1) ks_weight = (ks_weight - np.min(ks_weight)) / (np.max(ks_weight) - np.min(ks_weight)) ke_weight = 0 indicator = np.sqrt(ks_weight / (1 + ke_weight)) indicator = (indicator - np.min(indicator)) / (np.max(indicator) - np.min(indicator)) indicator_index = np.argsort(indicator) epoch = gl.get_value('epoch') temp = 0.5 # - epoch / 100.0 * 0.5 #print(temp) threshlod = indicator[indicator_index[int(indicator_index.shape[0] * temp)]] return indicator, threshlod
def __init__(self, inplanes, planes, spatial, reduction, stride=1, downsample=None): super(DynamicBlock, self).__init__() self.conv1 = conv3x3(inplanes, planes, stride) self.bn1 = nn.BatchNorm2d(planes) self.ispatial = gvar.get_value('is_spatial') self.dynamic_channel = DynamicChannelModule(inplanes, planes, reduction) self.lasso = gvar.get_value('lasso') if self.lasso: self.register_buffer('channel_l1', torch.tensor(1)) if self.ispatial: #self.dynamic_spatial = DynamicSpatialFcModule(spatial,planes,reduction,downsample) self.dynamic_spatial = DynamicSpatialConvModule(planes, stride) if self.lasso: self.register_buffer('spatial_l1', torch.tensor(1))
async def disconnect(self, code): # 关闭死循环读取日志 webuser = self.scope['user'].username if hasattr(gl, '_global_dict'): deploy_key = 'deploy_' + str(webuser) tail_key = 'tail_' + str(webuser) if deploy_key in gl._global_dict.keys(): gl.set_value(deploy_key, True) elif tail_key in gl._global_dict.keys(): client = gl.get_value(tail_key) client.close() await self.channel_layer.group_discard(webuser, self.channel_name)
def forward(self, input, weight_kse): weight = self.weight[None, :, None, None] #if 1 == 0: if self.planes is not None: iteration = gl.get_value('iteration') if iteration == 1: #weight = self.weight[None, :, None, None] output = torch.full_like(weight, 1) * 0.75 indicat, thre = KSE(weight_kse) for i in range(indicat.shape[0]): if (indicat[i] > thre) and weight.data[:, i, :, :] < 0.5: weight.data[:, i, :, :] = output.data[:, i, :, :] return input * weight
def local_tailf(self, logfile, webuser): f = open(logfile, 'rt') f.seek(0, 0) while True: is_stop = gl.get_value('deploy_' + str(webuser)) line = f.readline() if not line: time.sleep(0.2) continue elif is_stop: self.send_message(webuser, '[INFO]文件监视结束..') f.close() break self.send_message(webuser, line)
def dynamicresnet18(pretrained=False, **kwargs): """Constructs a ResNet-18 model. Args: pretrained (bool): If True, returns a model pre-trained on ImageNet """ dynamicmodel = dynamicResNet(DynamicResidualBasicBlock, [2, 2, 2, 2]) if pretrained: #only initialize model with pretrained weights resnet18 model = ResNet(BasicBlock, [2, 2, 2, 2]) model.load_state_dict(model_zoo.load_url(model_urls['resnet18'])) model_params = [] for _, v in model.state_dict().items(): model_params.append(v) idx = 0 for key, value in dynamicmodel.state_dict().items(): if "downsample" in key: value = model_params[idx] idx += 1 continue if "layer" not in key: value = model_params[idx] idx += 1 continue elif "layer" in key: if "dynamic" in key: if "conv" in key or "bn" in key: if value.shape != model_params[idx].shape: raise Exception("Params' shape not Equal!") value = model_params[idx] idx += 1 if idx != len(model_params): raise Exception("Transferred not Completed!") gvar.get_value('log').write('{}\n'.format( "Initialized Dynamicresnet18 from pretrained resnet18 success.")) gvar.get_value('log').flush() return dynamicmodel
def local_tail(self, logfile, webuser): # 创建一个可跨文件的全局变量,以便控制死循环 gl._init() gl.set_value('deploy_' + str(webuser), False) try: with open(logfile, 'rt') as f: f.seek(0, 0) while True: is_stop = gl.get_value('deploy_' + str(webuser)) line = f.readline() if line: self.send_message(webuser, line) elif is_stop: self.send_message(webuser, '[INFO]文件监视结束..') break except Exception as e: self.send_message(webuser, e)
def forward(self, input): removed_ratio = gvar.get_value('removed_ratio_c') if removed_ratio == 0: return input else: output = input.clone() temp = output.abs_() b, l = temp.size() removed_num = int(np.round( l * removed_ratio)) #remove removed_num elements. #removed_index = temp.argsort()[:,0:removed_num] # col index ### smallest k saved_num = l - removed_num removed_index = temp.argsort()[:, saved_num:] # col index ##### row_index = np.tile(np.arange(b), (removed_num, 1)).T output[row_index, removed_index] = 0 self.save_for_backward(output) return output
def mark_image(version1, version2): size = None # gen_img() # ** ImageFont模块** # 选择文字字体和大小 dirname = gl.get_value("dirname") font_path = '%s/font/microsoft_yahei_bold.ttf' % dirname file_default_path = "%s/images/kw_logo.png" % dirname file_new_img_path = "%s/images/kw_logo_mark_version.png" % dirname print(font_path, file_default_path, file_new_img_path) setFont = ImageFont.truetype(font_path, 120) # 设置文字颜色 fillColor = "#ffffff" # 蓝色 # version1 = "6.10.1" # version2 = "1.0.1" size = (1024, 1024) # 打开图片 image = pic_open(file_default_path) # 添加文字 pic_text(file_default_path, size, version1, version2, setFont, fillColor, file_new_img_path, direction=None)
def post(self, request, format=None): if request.data['excu'] == 'init': # 项目初始化 id = request.data['id'] result = self.repo_init(id) if result.exited == 0: Project.objects.filter(id=id).update(status='Succeed') info_logger.info('初始化项目:' + str(id) + ',执行成功!') http_status = OK msg = '初始化成功!' else: error_logger.error('初始化项目:%s 执行失败! 错误信息:%s' % (str(id), result.stderr)) http_status = BAD msg = '初始化项目:%s 执行失败! 错误信息:%s' % (str(id), result.stderr) return XopsResponse(msg, status=http_status) elif request.data['excu'] == 'deploy': # 部署操作 id = request.data['id'] webuser = request.user.username alias = request.data['alias'] self.start_time = time.strftime("%Y%m%d%H%M%S", time.localtime()) record_id = str(alias) + '_' + str(self.start_time) name = '部署_' + record_id DeployRecord.objects.create(name=name, alias=alias, status='Failed', project_id=int(id)) Project.objects.filter(id=id).update(last_task_status='Failed') local_log_path = self._path.rstrip('/') + '/' + str( id) + '_' + str(request.data['alias']) + '/logs' log = local_log_path + '/' + record_id + '.log' version = request.data['version'].strip() serverid = request.data['server_ids'] deploy = DeployExcu(webuser, record_id, id) deploy.start(log, version, serverid, record_id, webuser) return XopsResponse(record_id) elif request.data['excu'] == 'rollback': # 回滚 id = request.data['id'] project_id = request.data['project_id'] alias = request.data['alias'] self.start_time = time.strftime("%Y%m%d%H%M%S", time.localtime()) record_id = str(alias) + '_' + str(self.start_time) log = self._path.rstrip('/') + '/' + str(project_id) + '_' + str( alias) + '/logs/' + record_id + '.log' self.do_rollback(id, log, record_id) return XopsResponse(record_id) elif request.data['excu'] == 'deploymsg': # 部署控制台消息读取 try: id = request.data['id'] alias = request.data['alias'] record = request.data['record'] scenario = int(request.data['scenario']) logfile = self._path.rstrip('/') + '/' + str(id) + '_' + str( alias) + '/logs/' + record + '.log' webuser = request.user.username msg = Tailf() if scenario == 0: msg.local_tail(logfile, webuser) else: msg.read_file(logfile, webuser) http_status = OK request_status = '执行成功!' except Exception: http_status = BAD request_status = '执行错误:文件不存在!' return XopsResponse(request_status, status=http_status) elif request.data['excu'] == 'app_start': # 项目启动 try: app_start = request.data['app_start'] host = request.data['host'] webuser = request.user.username auth_info, auth_key = auth_init(host) connect = Shell(auth_info, connect_timeout=5, connect_kwargs=auth_key) app_start = app_start.strip().replace('&&', '').replace('||', '') commands = '/bin/bash -e %s' % (app_start) connect.run(commands, ws=True, webuser=webuser) connect.close() http_status = OK request_status = '执行成功!' except Exception as e: http_status = BAD request_status = '执行错误:' + str(e) return XopsResponse(request_status, status=http_status) elif request.data['excu'] == 'app_stop': # 项目停止 try: app_stop = request.data['app_stop'] host = request.data['host'] webuser = request.user.username auth_info, auth_key = auth_init(host) connect = Shell(auth_info, connect_timeout=5, connect_kwargs=auth_key) app_stop = app_stop.strip().replace('&&', '').replace('||', '') commands = '/bin/bash -e %s' % (app_stop) connect.run(commands, ws=True, webuser=webuser) connect.close() http_status = OK request_status = '执行成功!' except Exception as e: http_status = BAD request_status = '执行错误:' + str(e) return XopsResponse(request_status, status=http_status) elif request.data['excu'] == 'tail_start': # 日志监控 try: filter_text = str(request.data['filter']) app_log_file = request.data['app_log_file'] host = request.data['host'] webuser = request.user.username device_info = DeviceInfo.objects.filter(id=int(host)).values() host = device_info[0]['hostname'] auth_type = device_info[0]['auth_type'] connect_info = ConnectionInfo.objects.filter( hostname=host, auth_type=auth_type).values() user = connect_info[0]['username'] passwd = connect_info[0]['password'] port = connect_info[0]['port'] tail = Tailf() tail.remote_tail(host, port, user, passwd, app_log_file, webuser, filter_text=filter_text) http_status = OK request_status = '执行成功!' except Exception as e: http_status = BAD request_status = str(e) return XopsResponse(request_status, status=http_status) elif request.data['excu'] == 'tail_stop': # 日志监控停止 try: webuser = request.user.username if hasattr(gl, '_global_dict'): tail_key = 'tail_' + str(webuser) if tail_key in gl._global_dict.keys(): client = gl.get_value('tail_' + str(webuser)) client.close() http_status = OK request_status = '执行成功!' except Exception as e: http_status = BAD request_status = str(e) return XopsResponse(request_status, status=http_status)
def backward(self, grad_output): output = grad_output.clone() if gvar.get_value('removed_ratio_s') != 0: input, = self.saved_tensors output[input.eq(0)] = 0 return output