def _generator(self): for path, data in self.meta['videos'].items(): frames = set() for obj in data['objects'].values(): frames.update(obj['frames']) for frame in frames: ifn = f'train/JPEGImages/{path}/{frame}.jpg' ofn = f'train/Annotations/{path}/{frame}.png' with self.zf.open(ifn) as fp: im = utils.imdecode(fp) with self.zf.open(ofn) as fp: mask = utils.imdecode(fp, 0) for c in np.unique(mask): if c == 0: continue y = mask == c y.dtype = 'uint8' bbox = utils.find_bbox(y) if not bbox: continue x = utils.get_object(im, bbox) y = utils.get_object(y, bbox) x.shape = (1,) + x.shape y.shape = (1,) + y.shape + (1,) yield x.astype('float32'), y.astype('float32')
def hist_getter_sig_will(self,sample=None,ID=None,sys=None,pt_bin=None,eta_bin=None,prongs=None,var=None,newname=None,antiID=None): if sample is None: sample = 'ZtautauTruth' if var is None: var = 'evtsel_tau_nTrackTotal' if prongs is None: prongs = 'inc' if prongs == 'inc': h1P = self.hist_getter_sig_will(sample=sample,ID=ID,sys=sys,pt_bin=pt_bin,eta_bin=eta_bin,prongs='1P',var=var) hmP = self.hist_getter_sig_will(sample=sample,ID=ID,sys=sys,pt_bin=pt_bin,eta_bin=eta_bin,prongs='mP',var=var) if newname: h = h1P.Clone(newname) else: h = h1P.Clone() h.Add(hmP) return h IDtag = self.coepp_id_tag(ID) fname = self.filename_getter_sig(sys=sys,pt_bin=pt_bin,eta_bin=eta_bin,prongs=prongs,ID=ID) hname = 'h_%s_%s' % (var,sample) hpath = '%s/hists/%s' % (IDtag,hname) h = get_object(hpath,fname) if newname: h = h.Clone(newname) if antiID: hanti = self.hist_getter_sig_will(sample=sample,ID=antiID,sys=sys,pt_bin=pt_bin,eta_bin=eta_bin,prongs=prongs,var=var) h = hist_subtract_correlated(h,hanti) ## signal systematics print 'in hist getter, sys: ', sys if sys in self.sig_sys: hbits = ['h'] if prongs == '1P': hbits += ['1p'] elif prongs == 'mP': hbits += ['mp'] hbits += ['total_tracks', IDtag, 'Ztautau', sys, pt_bin, eta_bin, 'ratio' ] hname = '_'.join(hbits) fname = os.path.join(self.base_dir,self.filename_getter_sig_sys()) hsys = get_object(hname,fname) for i in xrange(h.GetNbinsX()+1): c = hsys.GetBinContent(i) ec = hsys.GetBinError(i) if not 0.5 < c < 1.5: c = 1. ec = 0.2 n = h.GetBinContent(i) en = h.GetBinError(i) if n: nnew = n*c ennew = sqrt(pow(ec/c,2)+pow(en/n,2)) * nnew #print 'bin%d, n: %.1f+-%.1f, c: %.3f+-%.3f, nnew: %.1f+-%.1f'%(i,n,en,c,ec,nnew,ennew) h.SetBinContent(i,nnew) h.SetBinError(i,ennew) #h.Multiply(hsys) return h
def get(self, request, project, pk): plan_obj = get_object(TestPlan, project, pk) if plan_obj.del_flag: return Response({'detail': unicode("Not found plan{}".format(pk))}, status=status.HTTP_400_BAD_REQUEST) serializer = TestPlanSerializer(plan_obj) return Response(serializer.data, status=status.HTTP_200_OK)
def get(self, request, project, pk): suite_obj = get_object(TestSuite, project, pk) if suite_obj.del_flag: return Response({'detail': unicode("Not found suite({})".format(pk))}, status=status.HTTP_400_BAD_REQUEST) serializer = TestsuiteSerializer(suite_obj) return Response(serializer.data, status=status.HTTP_200_OK)
def put(self, request, project, pk): serializer = PerDPDKTestcaseResultDetailSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) try: key = serializer.validated_data['key'] value = serializer.validated_data['value'] except KeyError: return Response( {'detail': unicode("The lack of required parameters.")}, status=status.HTTP_400_BAD_REQUEST) testcase_result_detail_obj = get_object(PerfDPDKTestCaseResultDetail, project, pk) if not check_app_attr(key, testcase_result_detail_obj.app, project): return Response( { 'detail': unicode("app ({0}) not have attribute ({1})".format( testcase_result_detail_obj.app.name, key.name)) }, status=status.HTTP_400_BAD_REQUEST) testcase_result_detail_obj.key = key testcase_result_detail_obj.value = value testcase_result_detail_obj.save() new_serializer = PerDPDKTestcaseResultDetailSerializer( testcase_result_detail_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def delete(self, request, project, pk): plan_obj = get_object(TestPlan, project, pk) plan_obj.del_flag = True plan_obj.testsuite_set.clear() plan_obj.save() return Response(status=status.HTTP_204_NO_CONTENT)
def put(self, request, project, pk): serializer = AppAttrSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) attr_name = serializer.data['name'] attr_list = AppAttr.objects.filter( name=serializer.validated_data['name'], app=serializer.validated_data['app'], project=get_project_object(project)) length = len(attr_list) if length > 1 or (length == 1 and attr_list[0].id != pk): return Response( { 'detail': unicode( "Found same name attr, please check your attr name.") }, status=status.HTTP_409_CONFLICT) attr_obj = get_object(AppAttr, project, pk) attr_obj.name = attr_name attr_obj.save() new_serializer = AppAttrSerializer(attr_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def get(self, request, project, pk): suiteresult_obj = get_object(PerfTestSuiteResult, project, pk) perf_caseresult_list = PerfDPDKTestCaseResult.objects.filter( perf_testsuite_result=suiteresult_obj) serializer = PerDPDKTestCaseResultSerializer(perf_caseresult_list, many=True) return Response(serializer.data, status=status.HTTP_200_OK)
def delete(self, request, project, pk): case_obj = get_object(TestCase, project, pk) case_obj.del_flag = True case_obj.testsuite.clear() case_obj.save() return Response(status=status.HTTP_204_NO_CONTENT)
def delete(self, request, project, pk): myresult_obj = get_object(MySuiteResult, project, pk) myresult_obj.del_flag = True myresult_obj.testsuite_set.clear() myresult_obj.save() return Response(status=status.HTTP_204_NO_CONTENT)
def put(self, request, project, pk): serializer = TestcaseResultSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) try: result = str(serializer.validated_data['result']).lower() bug = serializer.validated_data['bug'] log = serializer.validated_data['log'] comments = serializer.validated_data['comments'] except KeyError: return Response( {'detail': unicode("The lack of required parameters.")}, status=status.HTTP_400_BAD_REQUEST) caseresult_obj = get_object(TestCaseResult, project, pk) caseresult_obj.result = result caseresult_obj.bug = bug caseresult_obj.log = log caseresult_obj.comments = comments caseresult_obj.save() serializer = TestcaseResultSerializer(caseresult_obj) return Response(serializer.data, status=status.HTTP_202_ACCEPTED)
def main(fn): model = keras.models.load_model('weights.001.h5', compile=False) im = cv2.imread('00020.jpg') mask = cv2.imread('00020.png', 0) c = np.unique(mask)[0] y = mask == c y.dtype = 'uint8' bbox = utils.find_bbox(y) x = utils.get_object(im, bbox) y = utils.get_object(y, bbox) x.shape = (1,) + x.shape y.shape = (1,) + y.shape + (1,) x = x.astype('float32') masks = model.predict(x) cv2.imwrite('a.jpg', masks[0])
def put(self, request, project, pk): serializer = TestsuiteResultSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) try: #id = serializer.validated_data['id'] testexecution=serializer.validated_data['testexecution'] #id = serializer.validated_data['id'] testsuite=serializer.validated_data['testsuite'] passed=serializer.validated_data['passed'] failed=serializer.validated_data['failed'] block=serializer.validated_data['block'] na =serializer.validated_data['na'] total=serializer.validated_data['total'] #time=serializer.validated_data['time'] except KeyError: pass suiteresult_obj = get_object(TestPlan,project,pk) #suiteresult_obj.id=id suiteresult_obj.testexecution=testexecution suiteresult_obj.testsuite=testsuite suiteresult_obj.passed=passed suiteresult_obj.failed=failed suiteresult_obj.block=block suiteresult_obj.na=na suiteresult_obj.total=total suiteresult_obj.save() new_serializer = TestsuiteResultSerializer(suiteresult_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def put(self, request, project, pk): serializer = TestexecutionSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) try: name = serializer.validated_data['name'] runner = serializer.validated_data['runner'] except KeyError: return Response({'detail': unicode("The lack of required parameters.")}, status=status.HTTP_400_BAD_REQUEST) if not check_name_by_id(TestExecution, name, project, pk): return Response({'detail': unicode("Found same name testexecution_name, " "please check your testexecution_name name.")}, status=status.HTTP_409_CONFLICT) execution_obj = get_object(TestExecution, project, pk) if not check_owner_runner(execution_obj.runner, runner): return Response({'detail': unicode("The runner can not be changed.")}, status=status.HTTP_400_BAD_REQUEST) execution_obj.name = name execution_obj.runner = runner execution_obj.save() new_serializer = TestexecutionSerializer(execution_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def get(self, request, project, pk): caseresult_obj = get_object(PerfDPDKTestCaseResult, project, pk) casedetail_result_list = PerfDPDKTestCaseResultDetail.objects.filter( perf_dpdk_testcase_result=caseresult_obj) serializer = PerDPDKTestcaseResultDetailSerializer( casedetail_result_list, many=True) return Response(serializer.data, status=status.HTTP_200_OK)
def delete(self, request, project, pk): suite_obj = get_object(TestSuite, project, pk) suite_obj.del_flag = True suite_obj.testplan.clear() suite_obj.testcase_set.clear() suite_obj.save() return Response(status=status.HTTP_204_NO_CONTENT)
def get(self, request, project, pk): auth_status, message = check_auth(request.user, project, 'reader') if not auth_status: return Response(message, status=status.HTTP_401_UNAUTHORIZED) component_obj = get_object(Component, project, pk) serializer = FeatureComponentSerializer(component_obj) return Response(serializer.data, status=status.HTTP_200_OK)
def delete(self, request, project, pk): attr_obj = get_object(AppAttr, project, pk) app = App.objects.get(id=attr_obj.app_id) if app.testcase_set.count() or app.testsuite_set.count() or \ app.testplan_set.count() or app.testexecution_set.count(): return Response({'detail': unicode('This app has been used.')}) else: attr_obj.delete() return Response(status=status.HTTP_204_NO_CONTENT)
def delete(self, request, project, pk): auth_status, message = check_auth(request.user, project, 'writer') if not auth_status: return Response(message, status=status.HTTP_401_UNAUTHORIZED) component_obj = get_object(Component, project, pk) component_obj.feature_set.clear() component_obj.delete() return Response(status=status.HTTP_204_NO_CONTENT)
def put(self, request, project, pk): serializer = TestPlanSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) try: plan_name = serializer.validated_data['name'] plan_category = serializer.validated_data['category'] plan_owner = serializer.validated_data['owner'] plan_description = serializer.validated_data['description'] start_time = serializer.validated_data['start_time'] end_time = serializer.validated_data['end_time'] except KeyError: return Response( {'detail': unicode("The lack of required parameters.")}, status=status.HTTP_400_BAD_REQUEST) perf = serializer.validated_data.get('performance', False) app = serializer.validated_data.get('app', None) if not check_name_by_id( TestPlan, plan_name, project, pk, check_flag=True): return Response( { 'detail': unicode("Found same name testplan, " "please check your testplan name.") }, status=status.HTTP_409_CONFLICT) plan_obj = get_object(TestPlan, project, pk) if plan_obj.performance != perf or plan_obj.app != app: return Response( { 'detail': unicode("Not allow change performance and app attribute.") }, status=status.HTTP_400_BAD_REQUEST) if not check_owner_runner(plan_obj.owner, plan_owner): return Response( {'detail': unicode("The owner can not be changed.")}, status=status.HTTP_400_BAD_REQUEST) plan_obj.name = plan_name plan_obj.owner = plan_owner plan_obj.category = plan_category plan_obj.start_time = start_time plan_obj.end_time = end_time plan_obj.description = plan_description plan_obj.save() new_serializer = TestPlanSerializer(plan_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def put(self, request, project, pk): serializer = TestsuiteSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) try: suite_name = serializer.validated_data['name'] suite_subsystem = serializer.validated_data['subsystem'] suite_description = serializer.validated_data['description'] plan_list = serializer.validated_data['testplan'] except KeyError: return Response({'detail': unicode("The lack of required parameters.")}, status=status.HTTP_400_BAD_REQUEST) perf = serializer.validated_data.get('performance', False) app = serializer.validated_data.get('app', None) if perf and not app: return Response({'detail': unicode("parameter app must provide when performance=True")}, status=status.HTTP_400_BAD_REQUEST) if not perf and app: return Response({'detail': unicode("parameter app can not be set when performance=False")}, status=status.HTTP_400_BAD_REQUEST) if not check_name_by_id(TestSuite, suite_name, project, pk, check_flag=True): return Response({'detail': unicode("Found same name testsuite_name, " "please check your testsuite_name name.")}, status=status.HTTP_409_CONFLICT) suite_obj = get_object(TestSuite, project, pk) if suite_obj.performance != perf or suite_obj.app != app: return Response({'detail': unicode("Not allow change performance and app attribute.")}, status=status.HTTP_400_BAD_REQUEST) suite_obj.name = suite_name suite_obj.subsystem = suite_subsystem suite_obj.description = suite_description validated_plan_list = [] for plan in plan_list: if plan.performance != perf or plan.app != app: return Response({'detail': unicode("plan:{0} not match test suite of " "performance type".format(plan.id))}, status=status.HTTP_409_CONFLICT) validated_plan_list.append(plan) suite_obj.save() suite_obj.testplan.clear() for plan in validated_plan_list: suite_obj.testplan.add(plan) new_serializer = TestsuiteSerializer(suite_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def delete(self, request, project, pk): # Allow delete app when it not used by case,suite,plan,execution app_obj = get_object(App, project, pk) if app_obj.testcase_set.count() or app_obj.testsuite_set.count() or \ app_obj.testplan_set.count() or app_obj.testexecution_set.count() or \ app_obj.perftestcaseresultdetail_set.count(): return Response({'detail': unicode('This app has been used.')}) # Related AppAttr will auto delete before delete app. AppAttr.objects.filter(app=app_obj, project__name=project).delete() app_obj.delete() return Response(status=status.HTTP_204_NO_CONTENT)
def run(self, ctx): if not isinstance(ctx, IGraphicalClientContext): print('This script must be run within a graphical client') return plugins = ctx.getEnginesContext().getEnginesPlugins() for plugin in plugins: assert isinstance(plugin, IEnginesPlugin) if 'yoav' in plugin.getClass().getCanonicalName(): classloader = plugin.getClass().getClassLoader() # Update focused method UIBridge = utils.get_object("com.yoavst.jeb.bridge.UIBridge", classloader) UIBridge.update(ctx) # Get focused method dex_method = UIBridge.getFocusedMethod() if not dex_method: print "No selected method" return break else: print "JebOps is not installed" return assert isinstance(dex_method, IDexMethod) clz = dex_method.getClassType().getSignature()[1:-1].replace('/', '.') method = dex_method.getName(False) method = BasicMethodMap.get(method, method) sig = dex_method.getSignature(False) this_part = "" if (dex_method.getGenericFlags() & 8) == 8 else "this" if dex_method.getParameterTypes() and this_part: this_part += ", " params_list = ', '.join('"{}"'.format( self.signature_to_frida_signature(t.getSignature(False))) for t in dex_method.getParameterTypes()) args = [] for t in dex_method.getParameterTypes(): args.append(self.type_to_pretty_name(t, args)) args_list = ', '.join(args) fmt = FMT_VOID if dex_method.getReturnType().getSignature( ) == "V" else FMT_RET print fmt.format(class_name=clz, method_name=method, method_sig=sig, this_part=this_part, param_list=params_list, args_list=args_list)
def put(self, request, project, pk): serializer = TestexecutionOsSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) os_name = serializer.data['name'] if not check_name_by_id(OS, os_name, project, pk): return Response({'detail': unicode("Found same name os, please check your os name.")}, status=status.HTTP_409_CONFLICT) os_obj = get_object(OS, project, pk) os_obj.name = serializer.data['name'] os_obj.save() new_serializer = TestexecutionOsSerializer(os_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def hist_getter_sig_usyd(self,sample=None,ID=None,sys=None,pt_bin=None,eta_bin=None,prongs=None,var=None,newname=None,antiID=None): if sample is None: sample = 'ZtautauTruth' if var is None: var = 'evtsel_tau_nTrackTotal' if prongs is None: prongs = 'inc' kin_bin = self.get_kin_bin(pt_bin=pt_bin,eta_bin=eta_bin) IDtag = self.coepp_id_tag(ID) fname = self.filename_getter_sig(sys=sys,pt_bin=pt_bin,eta_bin=eta_bin,prongs=prongs,ID=ID) hname = 'h_%s_%s' % (var,sample) hpath = '%s_%s_%s/hists/%s' % (IDtag,prongs,kin_bin,hname) h = get_object(hpath,fname) if newname: h = h.Clone(newname) if antiID: hanti = self.hist_getter_sig_fed(sample=sample,ID=antiID,sys=sys,pt_bin=pt_bin,eta_bin=eta_bin,prongs=prongs,var=var) h = hist_subtract_correlated(h,hanti) return h
def run(self, ctx): assert isinstance(ctx, IGraphicalClientContext) try: plugins = ctx.getEnginesContext().getEnginesPlugins() for plugin in plugins: assert isinstance(plugin, IEnginesPlugin) if 'yoav' in plugin.getClass().getCanonicalName(): classloader = plugin.getClass().getClassLoader() print "Updating UI bridge" UIBridge = utils.get_object( "com.yoavst.jeb.bridge.UIBridge", classloader) UIBridge.update(ctx) break except: traceback.print_exc(file=sys.stdout)
def put(self, request, project, pk): serializer = TestcaseTypeSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) type_name = serializer.data['name'] if not check_name_by_id(TestCaseType, type_name, project, pk): return Response({'detail': unicode("Found same name type, " "please check your type name.")}, status=status.HTTP_409_CONFLICT) type_obj = get_object(TestCaseType, project, pk) type_obj.name = type_name type_obj.save() new_serializer = TestcaseTypeSerializer(type_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def put(self, request, project, pk): serializer = TestsuiteSubsystemSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) subsystem_name = serializer.data['name'] if not check_name_by_id(Subsystem, subsystem_name, project, pk): return Response({'detail': unicode("Found same name subsystem, " "please check your subsystem name.")}, status=status.HTTP_409_CONFLICT) subsystem_obj = get_object(Subsystem, project, pk) subsystem_obj.name = subsystem_name subsystem_obj.save() new_serializer = TestsuiteSubsystemSerializer(subsystem_obj) return Response(new_serializer.data, status=status.HTTP_202_ACCEPTED)
def hist_getter_abcd_fed(self,sample=None,region=None,ID=None,sys=None,pt_bin=None,eta_bin=None,var=None,newname=None, antiID=None): if sample is None: sample = 'data' if region is None: region = 'regA' if var is None: var = 'evtsel_tau_nTrackTotal' IDtag = self.coepp_id_tag(ID) if sys not in self.abcd_sys: sys = None fname = self.filename_getter_abcd(sys=sys,pt_bin=pt_bin,eta_bin=eta_bin,ID=ID) hname = 'h_%s_%s_%s' % (var,region,sample) hpath = '%s/%s/hists/%s' % (IDtag,region,hname) h = get_object(hpath,fname) if newname: h = h.Clone(newname) if antiID: hanti = self.hist_getter_abcd_fed(sample=sample,region=region,ID=antiID,sys=sys,pt_bin=pt_bin,eta_bin=eta_bin,var=var) h = hist_subtract_correlated(h,hanti) return h
def hist_getter_wcontrol_fed(self,sample=None,sign=None,ID=None,sys=None,pt_bin=None,eta_bin=None,var=None,newname=None,antiID=None): if sample is None: sample = 'data' if sign is None: sign = 'OS' if var is None: var = 'evtsel_tau_nTrackTotal' IDtag = self.coepp_id_tag(ID) w_sys = sys if sys in self.w_sys else None fname = self.filename_getter_wcontrol(sys=w_sys,pt_bin=pt_bin,eta_bin=eta_bin,ID=ID) hname = 'h_%s_%s' % (var,sample) hpath = '%s_%s/hists/%s' % (IDtag,sign,hname) h = get_object(hpath,fname) if newname: h = h.Clone(newname) if antiID: hanti = self.hist_getter_wcontrol_fed(sample=sample,sign=sign,ID=antiID,sys=sys,pt_bin=pt_bin,eta_bin=eta_bin,var=var) h = hist_subtract_correlated(h,hanti) return h