How to use get_label method in pypom_form

Best Python code snippet using pypom_form_python

AST_to_code.py

Source:AST_to_code.py Github

copy

Full Screen

...38 self.tokenizers = {}39 for vocab_type, token2index in token2index_dicts.items():40 self.tokenizers[vocab_type] = Tokenizer(self.output_folder, self.tokenized)41 self.tokenizers[vocab_type].load_from_dict(token2index)42 def get_label(self, node):43 if self.tokenized:44 if node.res:45 return self.tokenizers['RES'].get_label(node.token)46 else:47 parent_label = self.tokenizers['RES'].get_label(node.parent.token)48 if 'LITERAL' in parent_label: 49 return self.tokenizers['LITERAL'].get_label(node.token) 50 elif 'TYPE' == parent_label:51 return self.tokenizers['TYPE'].get_label(node.token)52 elif 'REF_BUILTIN' == parent_label:53 return self.tokenizers['NAME_BUILTIN'].get_label(node.token)54 else:55 return self.tokenizers['NAME'].get_label(node.token)56 else:57 return node.token58 def merge_terminals(self, terminals):59 return ' '.join([self.get_label(term) for term in terminals])60 def get_operator(self, ast_item):61 operator = self.get_label(ast_item).split('_')[-1]62 code = ''63 if 'BINARY' in self.get_label(ast_item) or 'COMPOUND_ASSIGNMENT' in self.get_label(ast_item):64 if len(ast_item.children) > 0:65 code += self.parse_node(ast_item.children[0])66 code += f' {operator} '67 if len(ast_item.children) > 1:68 code += self.parse_node(ast_item.children[1])69 elif 'UNARY' in self.get_label(ast_item):70 if 'POST' in self.get_label(ast_item):71 if len(ast_item.children) > 0:72 code += self.parse_node(ast_item.children[0])73 code += operator74 else:75 code += operator + ' '76 if len(ast_item.children) > 0:77 code += self.parse_node(ast_item.children[0])78 elif 'CONDITIONAL_OPERATOR' == self.get_label(ast_item):79 if len(ast_item.children) > 0:80 code += self.parse_node(ast_item.children[0])81 code += ' ? '82 if len(ast_item.children) > 1:83 code += self.parse_node(ast_item.children[1])84 code += ':'85 if len(ast_item.children) > 2:86 code += self.parse_node(ast_item.children[2])87 else:88 print(ast_item)89 pass90 return code91 def get_call_exp_operator(self, ast_item):92 code = ''93 operator_label = self.get_label(ast_item.children[0].children[0])94 operator = operator_label.split('operator')[-1]95 if operator == '[]':96 if len(ast_item.children[1].children) > 0:97 code += self.parse_node(ast_item.children[1].children[0])98 if len(ast_item.children[1].children) > 1:99 code += f'[{self.parse_node(ast_item.children[1].children[1])}]'100 elif operator == '()':101 if len(ast_item.children[1].children) > 0:102 code += self.parse_node(ast_item.children[1].children[0])103 if len(ast_item.children[1].children) > 1:104 code += f'({self.parse_node(ast_item.children[1].children[1])})'105 else:106 code += '()'107 elif operator == '*' or (len(ast_item.children) > 1 and len(ast_item.children[1].children) < 2):108 code += operator109 if len(ast_item.children[1].children) > 0:110 code += self.parse_node(ast_item.children[1].children[0])111 elif operator in ['++_PRE', '++_POST', '--_PRE', '--_POST']:112 if 'PRE' in operator:113 code += operator.split('_')[0]114 if len(ast_item.children[1].children) > 0:115 code += self.parse_node(ast_item.children[1].children[0])116 else:117 if len(ast_item.children[1].children) > 0:118 code += self.parse_node(ast_item.children[1].children[0])119 code += operator.split('_')[0]120 else:121 # first argument of operator122 if len(ast_item.children) > 1 and len(ast_item.children[1].children) > 0:123 code += self.parse_node(ast_item.children[1].children[0])124 code += f' {operator} '125 if len(ast_item.children) > 1 and len(ast_item.children[1].children) > 1:126 code += self.parse_node(ast_item.children[1].children[1]) 127 return code128 def get_var_decl(self, ast_item):129 # Contains all non-ref and non-type values130 # e.g. int ch[1][1] = {{2}} would give [1, 1, 2]131 declarations = []132 acc_spec = ''133 var_type = ''134 var_name = 'VAR_NAME_PLACEHOLDER'135 # If the variable is an array, this is will be filled136 array_sizes = []137 for child in ast_item.children:138 # Skip the type if this is a child of a declaration statement and not the first child139 # and the type is the same as the type of the first child140 if self.get_label(child) == 'TYPE_KIND' and \141 not (self.get_label(ast_item.parent) == 'DECL_STMT' \142 and ast_item != ast_item.parent.children[0]) and len(child.children) > 0:143 var_type_size = self.get_type(child.children[0])144 if type(var_type_size) is tuple:145 var_type += var_type_size[0]146 array_sizes = var_type_size[1]147 else:148 var_type = var_type_size149 elif self.get_label(child) == 'TYPE_KIND':150 var_type_size = self.get_type(child.children[0])151 if type(var_type_size) is tuple:152 array_sizes = var_type_size[1]153 154 elif self.get_label(child) == 'DECLARATOR':155 for decl_child in child.children:156 if self.get_label(decl_child) == 'NAME':157 var_name = self.merge_terminals(decl_child.children)158 else:159 declarations.append(self.parse_node(decl_child))160 elif self.get_label(child) == 'ACCESS_SPECIFIER':161 acc_spec += f'{self.merge_terminals(child.children).lower()}:\n' 162 ref_dims = ['[' + num + ']' for num in array_sizes]163 # initialize value the variable was initialized to (empty)164 var_value = ''165 # append initial values if set166 if len(declarations) > 0:167 var_value += ' = ' + ' '.join(declarations)168 # Combine the type of the variable with the name, dimensions and initial value169 return f'{acc_spec}{var_type} {var_name}{"".join(ref_dims)}{var_value}'170 def get_type(self, ast_item):171 type_string = ''172 if self.get_label(ast_item) == 'POINTER':173 type_string += self.get_type(ast_item.children[0])174 type_string += ' *'175 return type_string176 elif self.get_label(ast_item) == 'CONST_QUALIFIED':177 type_string += 'const '178 type_string += self.get_type(ast_item.children[0])179 return type_string180 elif self.get_label(ast_item) in ['TYPE', 'TYPE_REF']:181 if len(ast_item.children) > 0:182 return self.get_label(ast_item.children[0])183 else:184 return ''185 elif self.get_label(ast_item) == 'TYPE_ARRAY':186 array_sizes = []187 array_type = 'auto'188 for array_child in ast_item.children:189 if self.get_label(array_child) in ['TYPE', 'TYPE_REF', 'TYPE_RECORD']:190 array_type = self.get_type(array_child)191 elif self.get_label(array_child) == 'ARRAY_SIZES':192 for array_size in array_child.children:193 array_sizes.append(self.parse_node(array_size))194 type_string += array_type195 return (type_string, array_sizes)196 elif self.get_label(ast_item) == 'TYPE_RECORD':197 record_type = 'auto'198 for record_child in ast_item.children:199 if self.get_label(record_child) in ['TYPE', 'TYPE_REF']:200 record_type = self.get_type(record_child) 201 type_string += record_type202 for record_child in ast_item.children: 203 if self.get_label(record_child) == 'TYPE_RECORD_ELEMENTS':204 type_string += '<'205 for index, record_element in enumerate(record_child.children):206 type_string += self.get_type(record_element)207 if index < len(record_child.children)- 1:208 type_string += ', '209 type_string += '>'210 211 return type_string212 elif self.get_label(ast_item) == 'LVALUEREFERENCE':213 return self.get_type(ast_item.children[0]) + '&'214 elif self.get_label(ast_item) == 'RVALUEREFERENCE':215 return self.get_type(ast_item.children[0]) + '&&'216 else:217 return self.get_label(ast_item)218 219 220 def get_function_decl(self, ast_item):221 params = []222 acc_spec = ''223 return_type = ''224 const = ''225 func_name = ''226 for child in ast_item.children:227 if self.get_label(child) == 'TYPE_KIND':228 return_type += self.get_type(child.children[0])229 elif self.get_label(child) == 'PARM_DECL':230 params.append(self.get_var_decl(child))231 elif self.get_label(child) == 'NAME':232 func_name = self.merge_terminals(child.children)233 elif self.get_label(child) == 'ACCESS_SPECIFIER':234 acc_spec += f'{self.get_label(child.children[0]).lower()}:\n'235 elif self.get_label(child) == 'CONST':236 const += ' const'237 238 return f'{acc_spec}{return_type} {func_name}({", ".join(params)}){const}'239 def is_function(self, node):240 return self.get_label(node) in ['FUNCTION_DECL', 'FUNCTION_TEMPLATE',241 'CXX_METHOD', 'DESTRUCTOR', 'CONSTRUCTOR']242 def get_temp_type_param(self, ast_item):243 parameter_pack = False244 # If it is the last template type parameter, check if we need to add ... (=parameter pack -> zero or more params)245 if ast_item == ast_item.parent.children[-1]:246 function_decl_index = -1247 for index, child in enumerate(ast_item.parent.parent.children):248 if child == ast_item.parent:249 function_decl_index = index + 1250 if len(ast_item.parent.children) > function_decl_index and len(ast_item.parent.children[function_decl_index].children) > 1:251 last_parm_decl = ast_item.parent.parent.children[function_decl_index].children[-2].children[0].children[0]252 if self.get_label(last_parm_decl).endswith('...'):253 parameter_pack = True254 out = f'typename{"..." if parameter_pack else ""}'255 if len(ast_item.children) > 0:256 return out + f'{self.get_label(ast_item.children[0])}'257 else:258 return out259 def get_lambda_expr(self, ast_item):260 capture_clauses = []261 params = []262 for child in ast_item.children:263 if self.get_label(child) == 'CAPTURE_CLAUSE':264 capture_clauses.append(self.merge_terminals(child.children))265 elif self.get_label(child) == 'PARM_DECL':266 params.append(self.get_var_decl(child))267 268 return f'[{", ".join(capture_clauses)}]({", ".join(params)})'269 def parse_node(self, node):270 call_exp_operators = ['[]', '=', '<<', '>>', '==', '+', '-', '%', '*', '/',271 '+=', '-=', '^=', '||', '()', '!=',272 '++_PRE', '++_POST', '--_PRE', '--_POST']273 call_exp_operator_labels = ['operator' + op for op in call_exp_operators]274 code = ''275 if self.get_label(node) == 'VAR_DECL' or self.get_label(node) == 'FIELD_DECL' or self.get_label(node) == 'UNEXPOSED_DECL':276 code += self.get_var_decl(node)277 elif self.is_function(node):278 code += self.get_function_decl(node)279 for child in node.children:280 code += self.parse_node(child)281 elif self.get_label(node) == 'COMPOUND_STMT':282 code += ' {\n'283 for child in node.children:284 code += self.parse_node(child)285 code += '}\n'286 elif self.get_label(node) == 'PAREN_EXPR':287 code += '('288 for child in node.children:289 code += self.parse_node(child)290 code += ')'291 elif 'OPERATOR' in self.get_label(node) or 'UNARY_EXPR' in self.get_label(node):292 code += self.get_operator(node)293 elif self.get_label(node) == 'GNU_NULL_EXPR':294 code += 'NULL'295 elif self.get_label(node) == 'CXX_NULL_PTR_LITERAL_EXPR':296 code += 'nullptr'297 elif self.get_label(node) == 'COMPOUND_LITERAL_EXPR' or self.get_label(node) == 'CSTYLE_CAST_EXPR':298 code += '('299 code += self.parse_node(node.children[0]) if self.get_label(node) == 'COMPOUND_LITERAL_EXPR' else self.get_type(node.children[0].children[0])300 code += ')'301 for child in node.children[1:]:302 code += self.parse_node(child)303 elif self.get_label(node) in ['DECL_REF_EXPR', 'MEMBER_REF_EXPR', 'MEMBER_REF', 'LABEL_REF', 'REF', 'REF_BUILTIN'] or 'LITERAL' in self.get_label(node):304 for child in node.children[1:]:305 code += self.parse_node(child)306 code += '.'307 if self.get_label(node) == 'MEMBER_REF_EXPR' and len(node.children) > 1 \308 and self.get_label(node.children[1]) != 'CXX_THIS_EXPR': #node.parent.parent) == 'REF':309 code += '.'310 if len(node.children) > 0:311 code += self.get_label(node.children[0])312 # if self.get_label(node.parent) in ['REF', 'REF_BUILTIN']:313 # code += '.'314 elif self.get_label(node) == 'IF_STMT':315 code += 'if('316 # The first compound statement of an if statement is the code of the317 # if statement, the second (and also last) compound statement is for318 # a possible else statement319 compound_statements = 0320 for index, child in enumerate(node.children):321 if index == len(node.children) - 1 and compound_statements > 0:322 code += 'else '323 if self.get_label(child) == 'COMPOUND_STMT':324 compound_statements += 1325 code += self.parse_node(child)326 if index == 0:327 code += ')'328 elif self.get_label(node) == 'ARRAY_SUBSCRIPT_EXPR':329 if len(node.children) > 0:330 code += self.parse_node(node.children[0])331 code += '['332 if len(node.children) > 1:333 code += self.parse_node(node.children[1])334 335 code += ']'336 elif self.get_label(node) == 'RETURN_STMT':337 code += 'return'338 for child in node.children:339 code += ' '340 code += self.parse_node(child)341 elif self.get_label(node) == 'FOR_STMT':342 code += 'for('343 # Count amount of expressions in for loop (can essentialy be empty: for(;;))344 for_stmt_expressions = 0345 for child in node.children:346 if self.get_label(child) != 'COMPOUND_STMT':347 for_stmt_expressions += 1348 else:349 break350 # add ; for empty expressions e.g. if we have 2 expressions: for(;expr2;expr3)351 for _ in range(3 - for_stmt_expressions):352 code += ';'353 # add expressions354 for i in range(for_stmt_expressions):355 code += self.parse_node(node.children[i])356 if i < for_stmt_expressions - 1:357 code += '; '358 code += ')'359 # parse for loop compound statement360 for i in range(for_stmt_expressions, len(node.children)):361 code += self.parse_node(node.children[i])362 elif self.get_label(node) == 'CALL_EXPR':363 if len(node.children) > 0 and len(node.children[0].children) > 0 and self.get_label(node.children[0].children[0]) in call_exp_operator_labels:364 code += self.get_call_exp_operator(node)365 else:366 for idx, child in enumerate(reversed(node.children)):367 if self.get_label(child) != 'ARGUMENTS':368 code += self.parse_node(child)369 if self.get_label(child) != 'TYPE_REF' and idx < len(node.children) - 1:370 code += '.'371 code += '('372 for child in node.children: 373 # # for child in node.children:374 # # if self.get_label(child) in ['NAME', 'REF', 'REF_BUILTIN']:375 if self.get_label(child) == 'ARGUMENTS':376 for index, arg in enumerate(child.children):377 code += self.parse_node(arg)378 if index < len(child.children) - 1:379 code += ', '380 code += ')'381 elif self.get_label(node) == 'TYPE_CALL_EXPR':382 for child in node.children:383 if self.get_label(child) == 'TYPE_KIND':384 code += self.get_type(child.children[0]) + '('385 elif self.get_label(child) == 'ARGUMENTS':386 for index, arg in enumerate(child.children):387 code += self.parse_node(arg)388 if index < len(child.children) - 1:389 code += ', '390 code += ')'391 392 elif self.get_label(node) == 'TYPEDEF_DECL':393 for child in node.children:394 if self.get_label(child) == 'TYPE_DEF':395 code += f'typedef {self.get_type(child.children[0])} '396 elif self.get_label(child) == 'IDENTIFIER':397 code += self.get_label(child.children[0])398 elif self.get_label(node) == 'WHILE_STMT':399 code += 'while('400 code += self.parse_node(node.children[0])401 code += ')'402 code += self.parse_node(node.children[1])403 elif self.get_label(node) == 'TYPE_REF' or self.get_label(node) == 'TYPE':404 code += self.get_type(node)405 if self.get_label(node.parent) != 'COMPOUND_LITERAL_EXPR' and not 'CAST' in self.get_label(node.parent):406 code += '::'407 elif self.get_label(node) == 'CLASS_DECL':408 code += 'class '409 for child in node.children:410 if self.get_label(child) == 'NAME':411 code += self.merge_terminals(child.children)412 else:413 code += self.parse_node(child)414 elif self.get_label(node) == 'STRUCT_DECL':415 code += 'struct '416 for child in node.children:417 if self.get_label(child) == 'NAME':418 code += self.merge_terminals(child.children)419 else:420 code += self.parse_node(child)421 elif self.get_label(node) in ['BREAK_STMT', 'CONTINUE_STMT']:422 code += self.get_label(node).split('_')[0].lower()423 elif self.get_label(node) == 'CXX_FOR_RANGE_STMT':424 code += 'for('425 code += self.parse_node(node.children[0])426 code += ':'427 code += self.parse_node(node.children[1])428 code += ')'429 for child in node.children[2:]:430 code += self.parse_node(child)431 elif self.get_label(node) == 'INIT_LIST_EXPR':432 code += '{'433 for index, child in enumerate(node.children):434 code += self.parse_node(child)435 if index < len(node.children) - 1:436 code += ','437 code += '}'438 elif self.get_label(node) == 'DECL_STMT':439 for index, child in enumerate(node.children):440 code += self.parse_node(child)441 if index < len(node.children) - 1:442 code += ','443 elif self.get_label(node) == 'TEMPLATE_DECL':444 code += 'template<'445 for index, child in enumerate(node.children):446 code += self.parse_node(child)447 if index < len(node.children) - 1:448 code += ','449 code += '>\n'450 elif self.get_label(node) == 'TEMPLATE_TYPE_PARAMETER':451 code += self.get_temp_type_param(node)452 elif self.get_label(node) == 'CXX_FUNCTIONAL_CAST_EXPR':453 code += f'{ self.get_type(node.children[0].children[0])}('454 for child in node.children[1:]:455 code += self.parse_node(child)456 457 code += ')'458 elif self.get_label(node) == 'CONSTRUCTOR_INITIALIZER':459 constr_inits = []460 for child in node.parent.children:461 if self.get_label(child) == 'CONSTRUCTOR_INITIALIZER':462 constr_inits.append(child)463 # If first constr init, add ' : '464 if node == constr_inits[0]:465 code += ' : '466 467 code += self.parse_node(node.children[0]) + '('468 if len(node.children) > 1:469 code += self.parse_node(node.children[1])470 code += ')'471 # If not last constr init, place comma in between constr inits472 if node != constr_inits[-1]:473 code += ', '474 elif self.get_label(node) == 'PACK_EXPANSION_EXPR':475 for child in node.children:476 code += self.parse_node(child)477 code += '...'478 elif self.get_label(node) == 'CXX_THIS_EXPR':479 if self.get_label(node.parent) == 'MEMBER_REF_EXPR':480 code += 'this->'481 else:482 code += 'this'483 elif self.get_label(node) == 'SWITCH_STMT':484 code += 'switch('485 code += self.parse_node(node.children[0])486 code += ')'487 for child in node.children[1:]:488 code += self.parse_node(child)489 elif self.get_label(node) == 'CASE_STMT':490 code += 'case '491 code += self.parse_node(node.children[0])492 code += ':\n'493 for child in node.children[1:]:494 code += self.parse_node(child)495 elif self.get_label(node) == 'CXX_TRY_STMT':496 code += 'try'497 for child in node.children:498 code += self.parse_node(child)499 elif self.get_label(node) == 'CXX_CATCH_STMT':500 if len(node.children) < 2:501 code += 'catch(...)'502 for child in node.children:503 code += self.parse_node(child)504 505 else:506 code += 'catch('507 code += self.parse_node(node.children[0])508 code += ')'509 for child in node.children[1:]:510 code += self.parse_node(child)511 elif self.get_label(node) == 'LAMBDA_EXPR':512 code += self.get_lambda_expr(node)513 for child in node.children:514 code += self.parse_node(child)515 elif self.get_label(node) == 'CXX_STATIC_CAST_EXPR':516 code += f'static_cast<{self.get_label(node.children[0].children[0])}>('517 for child in node.children[1:]:518 code += self.parse_node(child)519 code += ')'520 elif self.get_label(node) == 'DO_STMT':521 code += 'do'522 code += self.parse_node(node.children[0])523 code += 'while('524 for child in node.children[1:]:525 code += self.parse_node(child)526 code += ')'527 elif self.get_label(node) == 'GOTO_STMT':528 code += 'goto '529 for child in node.children:530 code += self.parse_node(child)531 elif self.get_label(node) == 'LABEL_STMT':532 for label_child in node.children:533 if self.get_label(label_child) == 'NAME':534 label_name = self.merge_terminals(label_child.children)535 code += f'{label_name}:\n'536 else:537 code += self.parse_node(label_child)538 # elif self.get_label(node) == 'TYPE_KIND':539 # code += self.get_type(node.children[0])540 # print(node.parent, node.children[0].children)541 else:542 # print(self.get_label(node))543 pass544 if ('COMPOUND_STMT' in self.get_label(node.parent) \545 or self.get_label(node.parent) == 'root' \546 # If statement one-liner with no compound statement (= {..}), we still want ";" after each line547 or (self.get_label(node.parent) == 'IF_STMT' \548 and 'COMPOUND_STMT' not in [self.get_label(c) for c in node.parent.children] \549 and node != node.parent.children[0])) \550 and (self.get_label(node) != 'FUNCTION_DECL' \551 and self.get_label(node) != 'IF_STMT' \552 and self.get_label(node) != 'FOR_STMT' \553 and self.get_label(node) != 'CXX_FOR_RANGE_STMT' \554 and self.get_label(node) != 'WHILE_STMT' \555 and self.get_label(node) != 'TEMPLATE_DECL') \556 or (self.get_label(node) == 'FUNCTION_DECL' and 'COMPOUND_STMT' not in [self.get_label(c) for c in node.children]):557 code += ';\n'558 return code559 def thread_parser(self, file_queue, pbar, output_folder, imports):560 while not file_queue.empty():561 ast_id, ast = file_queue.get()562 root = self.importer.import_(ast)563 output = open(f'{output_folder}{ast_id}.cpp', 'w')564 565 try:566 for child in root.children:567 output.write(self.parse_node(child))568 except Exception as e:569 print(f'File: {ast_id} failed: {e}')570 pbar.update()...

Full Screen

Full Screen

Face_Recognition_Tflearn.py

Source:Face_Recognition_Tflearn.py Github

copy

Full Screen

...24shape_predictor = dlib.shape_predictor(predictor_path)25face_recog = dlib.face_recognition_model_v1(face_recog_model_path)262728def get_label(key):29 label = []30 for i in range(num_faces):31 if key == i:32 label.append(1)33 else:34 label.append(0)3536 print(label)37 return label383940for folder_name in tqdm(os.listdir(image_dir)):41 count = 042 folder_path = os.path.join(image_dir, folder_name)43 for image_name in os.listdir(folder_path):44 image_path = os.path.join(folder_path, image_name)45 img = cv2.imread(image_path)46 dets = detector(img, 1)47 print("Number of faces detected", len(dets))48 if len(dets) == 0 or len(dets) > 1:49 pass50 else:51 for k, d in enumerate(dets):52 print("Detection {}: Left : {} Top: {} Right: {} Bottom: {}".format(k, d.left(), d.top(), d.right(), d.bottom()))53 shape = shape_predictor(img, d)54 face_descriptor = face_recog.compute_face_descriptor(img, shape)55 # print(face_descriptor)56 # print(len(face_descriptor))57 if count < num_shots:58 num_train += 159 feature_vector_train.append([face_descriptor])60 # if folder_name == "Nikhil":61 # labels_train.append(get_label(0))62 # elif folder_name == "Nikita":63 # labels_train.append(get_label(1))64 # elif folder_name == "Chaitanya":65 # labels_train.append(get_label(2))66 # elif folder_name == "Deep":67 # labels_train.append(get_label(3))68 if folder_name == "Aamir Khan":69 labels_train.append(get_label(0))70 elif folder_name == "AJ Styles":71 labels_train.append(get_label(1))72 elif folder_name == "Anushka Sharma":73 labels_train.append(get_label(2))74 elif folder_name == "Bebe Rexa":75 labels_train.append(get_label(3))76 elif folder_name == "Biswa Kalyan Rath":77 labels_train.append(get_label(4))78 elif folder_name == "Brad Pitt":79 labels_train.append(get_label(5))80 elif folder_name == "Chris Jericho":81 labels_train.append(get_label(6))82 elif folder_name == "Dwayne Johnson":83 labels_train.append(get_label(7))84 elif folder_name == "Gigi":85 labels_train.append(get_label(8))86 elif folder_name == "Harvey Specter":87 labels_train.append(get_label(9))88 elif folder_name == "Jacqueline Fernandez":89 labels_train.append(get_label(10))90 elif folder_name == "Jaime Presley":91 labels_train.append(get_label(11))92 elif folder_name == "Jeff Bezos":93 labels_train.append(get_label(12))94 elif folder_name == "Jeff Hardy":95 labels_train.append(get_label(13))96 elif folder_name == "Margot Robbie":97 labels_train.append(get_label(14))98 elif folder_name == "Matt Leblanc":99 labels_train.append(get_label(15))100 elif folder_name == "Modi Ji":101 labels_train.append(get_label(16))102 elif folder_name == "Mukesh Ambani":103 labels_train.append(get_label(17))104 elif folder_name == "Parineeti Chopra":105 labels_train.append(get_label(18))106 elif folder_name == "Ranbir Kapoor":107 labels_train.append(get_label(19))108 elif folder_name == "Ravindra Jadeja":109 labels_train.append(get_label(20))110 elif folder_name == "Salman Khan":111 labels_train.append(get_label(21))112 elif folder_name == "Shahrukh Khan":113 labels_train.append(get_label(22))114 elif folder_name == "Tim Cook":115 labels_train.append(get_label(23))116 elif folder_name == "Virat Kohli":117 labels_train.append(get_label(24))118 elif folder_name == "Nikhil":119 labels_train.append(get_label(25))120 elif folder_name == "Nikita":121 labels_train.append(get_label(26))122 elif folder_name == "Chaitanya":123 labels_train.append(get_label(27))124 elif folder_name == "Deep":125 labels_train.append(get_label(28))126 elif folder_name == "Class 31":127 labels_train.append(get_label(29))128 elif folder_name == "Class 32":129 labels_train.append(get_label(30))130 elif folder_name == "Class 33":131 labels_train.append(get_label(31))132 elif folder_name == "Class 34":133 labels_train.append(get_label(32))134 elif folder_name == "Class 35":135 labels_train.append(get_label(33))136 elif folder_name == "Class 36":137 labels_train.append(get_label(34))138 elif folder_name == "Class 37":139 labels_train.append(get_label(35))140 elif folder_name == "Class 38":141 labels_train.append(get_label(36))142 elif folder_name == "Class 39":143 labels_train.append(get_label(37))144 elif folder_name == "Class 40":145 labels_train.append(get_label(38))146 elif folder_name == "Class 41":147 labels_train.append(get_label(39))148 elif folder_name == "Class 42":149 labels_train.append(get_label(40))150 elif folder_name == "Class 43":151 labels_train.append(get_label(41))152 elif folder_name == "Class 44":153 labels_train.append(get_label(42))154 elif folder_name == "Class 45":155 labels_train.append(get_label(43))156 elif folder_name == "Class 46":157 labels_train.append(get_label(44))158 elif folder_name == "Class 47":159 labels_train.append(get_label(45))160 elif folder_name == "Class 48":161 labels_train.append(get_label(46))162 elif folder_name == "Class 49":163 labels_train.append(get_label(47))164 elif folder_name == "Class 50":165 labels_train.append(get_label(48))166 else:167 labels_train.append(get_label(49)) # For Unauthorized person168 else:169 num_test += 1170 feature_vector_test.append([face_descriptor])171 # if folder_name == "Nikhil":172 # labels_test.append(get_label(0))173 # elif folder_name == "Nikita":174 # labels_test.append(get_label(1))175 # elif folder_name == "Chaitanya":176 # labels_test.append(get_label(2))177 # elif folder_name == "Deep":178 # labels_test.append(get_label(3))179 if folder_name == "Aamir Khan":180 labels_test.append(get_label(0))181 elif folder_name == "AJ Styles":182 labels_test.append(get_label(1))183 elif folder_name == "Anushka Sharma":184 labels_test.append(get_label(2))185 elif folder_name == "Bebe Rexa":186 labels_test.append(get_label(3))187 elif folder_name == "Biswa Kalyan Rath":188 labels_test.append(get_label(4))189 elif folder_name == "Brad Pitt":190 labels_test.append(get_label(5))191 elif folder_name == "Chris Jericho":192 labels_test.append(get_label(6))193 elif folder_name == "Dwayne Johnson":194 labels_test.append(get_label(7))195 elif folder_name == "Gigi":196 labels_test.append(get_label(8))197 elif folder_name == "Harvey Specter":198 labels_test.append(get_label(9))199 elif folder_name == "Jacqueline Fernandez":200 labels_test.append(get_label(10))201 elif folder_name == "Jaime Presley":202 labels_test.append(get_label(11))203 elif folder_name == "Jeff Bezos":204 labels_test.append(get_label(12))205 elif folder_name == "Jeff Hardy":206 labels_test.append(get_label(13))207 elif folder_name == "Margot Robbie":208 labels_test.append(get_label(14))209 elif folder_name == "Matt Leblanc":210 labels_test.append(get_label(15))211 elif folder_name == "Modi Ji":212 labels_test.append(get_label(16))213 elif folder_name == "Mukesh Ambani":214 labels_test.append(get_label(17))215 elif folder_name == "Parineeti Chopra":216 labels_test.append(get_label(18))217 elif folder_name == "Ranbir Kapoor":218 labels_test.append(get_label(19))219 elif folder_name == "Ravindra Jadeja":220 labels_test.append(get_label(20))221 elif folder_name == "Salman Khan":222 labels_test.append(get_label(21))223 elif folder_name == "Shahrukh Khan":224 labels_test.append(get_label(22))225 elif folder_name == "Tim Cook":226 labels_test.append(get_label(23))227 elif folder_name == "Virat Kohli":228 labels_test.append(get_label(24))229 elif folder_name == "Nikhil":230 labels_test.append(get_label(25))231 elif folder_name == "Nikita":232 labels_test.append(get_label(26))233 elif folder_name == "Chaitanya":234 labels_test.append(get_label(27))235 elif folder_name == "Deep":236 labels_test.append(get_label(28))237 elif folder_name == "Class 31":238 labels_test.append(get_label(29))239 elif folder_name == "Class 32":240 labels_test.append(get_label(30))241 elif folder_name == "Class 33":242 labels_test.append(get_label(31))243 elif folder_name == "Class 34":244 labels_test.append(get_label(32))245 elif folder_name == "Class 35":246 labels_test.append(get_label(33))247 elif folder_name == "Class 36":248 labels_test.append(get_label(34))249 elif folder_name == "Class 37":250 labels_test.append(get_label(35))251 elif folder_name == "Class 38":252 labels_test.append(get_label(36))253 elif folder_name == "Class 39":254 labels_test.append(get_label(37))255 elif folder_name == "Class 40":256 labels_test.append(get_label(38))257 elif folder_name == "Class 41":258 labels_test.append(get_label(39))259 elif folder_name == "Class 42":260 labels_test.append(get_label(40))261 elif folder_name == "Class 43":262 labels_test.append(get_label(41))263 elif folder_name == "Class 44":264 labels_test.append(get_label(42))265 elif folder_name == "Class 45":266 labels_test.append(get_label(43))267 elif folder_name == "Class 46":268 labels_test.append(get_label(44))269 elif folder_name == "Class 47":270 labels_test.append(get_label(45))271 elif folder_name == "Class 48":272 labels_test.append(get_label(46))273 elif folder_name == "Class 49":274 labels_test.append(get_label(47))275 elif folder_name == "Class 50":276 labels_test.append(get_label(48))277 else:278 labels_test.append(get_label(49)) # For Unauthorized person279 count += 1280281#feature_vector_train = np.load("feature_vector_train.npy")282#feature_vector_test = np.load("feature_vector_test.npy")283print()284print()285print(len(feature_vector_train))286print(len(labels_train))287# num_train = 24288# num_test = 17289feature_vector_train = np.array(feature_vector_train).reshape(num_train, 128, 1, 1)290# random.shuffle(feature_vector_train)291np.save("feature_vector_train.npy", feature_vector_train)292feature_vector_test = np.array(feature_vector_test).reshape(num_test, 128, 1, 1) ...

Full Screen

Full Screen

fields.py

Source:fields.py Github

copy

Full Screen

...54 if self.allow_blank:55 yield ('__None', self.blank_text, self.data is None)56 for obj in self.query:57 key = str(obj.key())58 label = self.get_label(obj)59 yield (key, label, (self.data.key() == obj.key()) if self.data else False)60 def process_formdata(self, valuelist):61 if valuelist:62 if valuelist[0] == '__None':63 self.data = None64 else:65 self._data = None66 self._formdata = valuelist[0]67 def pre_validate(self, form):68 if not self.allow_blank or self.data is not None:69 for obj in self.query:70 if str(self.data.key()) == str(obj.key()):71 break72 else:73 raise ValueError(self.gettext('Not a valid choice'))74class KeyPropertyField(fields.SelectFieldBase):75 """76 A field for ``ndb.KeyProperty``. The list items are rendered in a select.77 :param reference_class:78 A db.Model class which will be used to generate the default query79 to make the list of items. If this is not specified, The `query`80 property must be overridden before validation.81 :param get_label:82 If a string, use this attribute on the model class as the label83 associated with each option. If a one-argument callable, this callable84 will be passed model instance and expected to return the label text.85 Otherwise, the model object's `__str__` or `__unicode__` will be used.86 :param allow_blank:87 If set to true, a blank choice will be added to the top of the list88 to allow `None` to be chosen.89 :param blank_text:90 Use this to override the default blank option's label.91 """92 widget = widgets.Select()93 def __init__(self, label=None, validators=None, reference_class=None,94 get_label=None, allow_blank=False, blank_text='', **kwargs):95 super(KeyPropertyField, self).__init__(label, validators, **kwargs)96 if get_label is None:97 self.get_label = lambda x: x98 elif isinstance(get_label, basestring):99 self.get_label = operator.attrgetter(get_label)100 else:101 self.get_label = get_label102 self.allow_blank = allow_blank103 self.blank_text = blank_text104 self._set_data(None)105 if reference_class is not None:106 self.query = reference_class.query()107 def _get_data(self):108 if self._formdata is not None:109 for obj in self.query:110 if str(obj.key.id()) == self._formdata:111 self._set_data(obj)112 break113 return self._data114 def _set_data(self, data):115 self._data = data116 self._formdata = None117 data = property(_get_data, _set_data)118 def iter_choices(self):119 if self.allow_blank:120 yield ('__None', self.blank_text, self.data is None)121 for obj in self.query:122 key = str(obj.key.id())123 label = self.get_label(obj)124 yield (key, label, (self.data.key == obj.key) if self.data else False)125 def process_formdata(self, valuelist):126 if valuelist:127 if valuelist[0] == '__None':128 self.data = None129 else:130 self._data = None131 self._formdata = valuelist[0]132 def pre_validate(self, form):133 if self.data is not None:134 for obj in self.query:135 if self.data.key == obj.key:136 break137 else:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pypom_form automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful