How to use example method in pandera

Best Python code snippet using pandera_python

data_utils.py

Source:data_utils.py Github

copy

Full Screen

1# Copyright 2016 Google Inc. All Rights Reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14# ==============================================================================15"""Functions for constructing vocabulary, converting the examples to integer format and building the required masks for batch computation Author: aneelakantan (Arvind Neelakantan)16"""17import copy18import numbers19import numpy as np20import wiki_data21def return_index(a):22 for i in range(len(a)):23 if (a[i] == 1.0):24 return i25def construct_vocab(data, utility, add_word=False):26 ans = []27 for example in data:28 sent = ""29 for word in example.question:30 if (not (isinstance(word, numbers.Number))):31 sent += word + " "32 example.original_nc = copy.deepcopy(example.number_columns)33 example.original_wc = copy.deepcopy(example.word_columns)34 example.original_nc_names = copy.deepcopy(example.number_column_names)35 example.original_wc_names = copy.deepcopy(example.word_column_names)36 if (add_word):37 continue38 number_found = 039 if (not (example.is_bad_example)):40 for word in example.question:41 if (isinstance(word, numbers.Number)):42 number_found += 143 else:44 if (not (utility.word_ids.has_key(word))):45 utility.words.append(word)46 utility.word_count[word] = 147 utility.word_ids[word] = len(utility.word_ids)48 utility.reverse_word_ids[utility.word_ids[word]] = word49 else:50 utility.word_count[word] += 151 for col_name in example.word_column_names:52 for word in col_name:53 if (isinstance(word, numbers.Number)):54 number_found += 155 else:56 if (not (utility.word_ids.has_key(word))):57 utility.words.append(word)58 utility.word_count[word] = 159 utility.word_ids[word] = len(utility.word_ids)60 utility.reverse_word_ids[utility.word_ids[word]] = word61 else:62 utility.word_count[word] += 163 for col_name in example.number_column_names:64 for word in col_name:65 if (isinstance(word, numbers.Number)):66 number_found += 167 else:68 if (not (utility.word_ids.has_key(word))):69 utility.words.append(word)70 utility.word_count[word] = 171 utility.word_ids[word] = len(utility.word_ids)72 utility.reverse_word_ids[utility.word_ids[word]] = word73 else:74 utility.word_count[word] += 175def word_lookup(word, utility):76 if (utility.word_ids.has_key(word)):77 return word78 else:79 return utility.unk_token80def convert_to_int_2d_and_pad(a, utility):81 ans = []82 #print a83 for b in a:84 temp = []85 if (len(b) > utility.FLAGS.max_entry_length):86 b = b[0:utility.FLAGS.max_entry_length]87 for remaining in range(len(b), utility.FLAGS.max_entry_length):88 b.append(utility.dummy_token)89 assert len(b) == utility.FLAGS.max_entry_length90 for word in b:91 temp.append(utility.word_ids[word_lookup(word, utility)])92 ans.append(temp)93 #print ans94 return ans95def convert_to_bool_and_pad(a, utility):96 a = a.tolist()97 for i in range(len(a)):98 for j in range(len(a[i])):99 if (a[i][j] < 1):100 a[i][j] = False101 else:102 a[i][j] = True103 a[i] = a[i] + [False] * (utility.FLAGS.max_elements - len(a[i]))104 return a105seen_tables = {}106def partial_match(question, table, number):107 answer = []108 match = {}109 for i in range(len(table)):110 temp = []111 for j in range(len(table[i])):112 temp.append(0)113 answer.append(temp)114 for i in range(len(table)):115 for j in range(len(table[i])):116 for word in question:117 if (number):118 if (word == table[i][j]):119 answer[i][j] = 1.0120 match[i] = 1.0121 else:122 if (word in table[i][j]):123 answer[i][j] = 1.0124 match[i] = 1.0125 return answer, match126def exact_match(question, table, number):127 #performs exact match operation128 answer = []129 match = {}130 matched_indices = []131 for i in range(len(table)):132 temp = []133 for j in range(len(table[i])):134 temp.append(0)135 answer.append(temp)136 for i in range(len(table)):137 for j in range(len(table[i])):138 if (number):139 for word in question:140 if (word == table[i][j]):141 match[i] = 1.0142 answer[i][j] = 1.0143 else:144 table_entry = table[i][j]145 for k in range(len(question)):146 if (k + len(table_entry) <= len(question)):147 if (table_entry == question[k:(k + len(table_entry))]):148 #if(len(table_entry) == 1):149 #print "match: ", table_entry, question150 match[i] = 1.0151 answer[i][j] = 1.0152 matched_indices.append((k, len(table_entry)))153 return answer, match, matched_indices154def partial_column_match(question, table, number):155 answer = []156 for i in range(len(table)):157 answer.append(0)158 for i in range(len(table)):159 for word in question:160 if (word in table[i]):161 answer[i] = 1.0162 return answer163def exact_column_match(question, table, number):164 #performs exact match on column names165 answer = []166 matched_indices = []167 for i in range(len(table)):168 answer.append(0)169 for i in range(len(table)):170 table_entry = table[i]171 for k in range(len(question)):172 if (k + len(table_entry) <= len(question)):173 if (table_entry == question[k:(k + len(table_entry))]):174 answer[i] = 1.0175 matched_indices.append((k, len(table_entry)))176 return answer, matched_indices177def get_max_entry(a):178 e = {}179 for w in a:180 if (w != "UNK, "):181 if (e.has_key(w)):182 e[w] += 1183 else:184 e[w] = 1185 if (len(e) > 0):186 (key, val) = sorted(e.items(), key=lambda x: -1 * x[1])[0]187 if (val > 1):188 return key189 else:190 return -1.0191 else:192 return -1.0193def list_join(a):194 ans = ""195 for w in a:196 ans += str(w) + ", "197 return ans198def group_by_max(table, number):199 #computes the most frequently occuring entry in a column200 answer = []201 for i in range(len(table)):202 temp = []203 for j in range(len(table[i])):204 temp.append(0)205 answer.append(temp)206 for i in range(len(table)):207 if (number):208 curr = table[i]209 else:210 curr = [list_join(w) for w in table[i]]211 max_entry = get_max_entry(curr)212 #print i, max_entry213 for j in range(len(curr)):214 if (max_entry == curr[j]):215 answer[i][j] = 1.0216 else:217 answer[i][j] = 0.0218 return answer219def pick_one(a):220 for i in range(len(a)):221 if (1.0 in a[i]):222 return True223 return False224def check_processed_cols(col, utility):225 return True in [226 True for y in col227 if (y != utility.FLAGS.pad_int and y !=228 utility.FLAGS.bad_number_pre_process)229 ]230def complete_wiki_processing(data, utility, train=True):231 #convert to integers and padding232 processed_data = []233 num_bad_examples = 0234 for example in data:235 number_found = 0236 if (example.is_bad_example):237 num_bad_examples += 1238 if (not (example.is_bad_example)):239 example.string_question = example.question[:]240 #entry match241 example.processed_number_columns = example.processed_number_columns[:]242 example.processed_word_columns = example.processed_word_columns[:]243 example.word_exact_match, word_match, matched_indices = exact_match(244 example.string_question, example.original_wc, number=False)245 example.number_exact_match, number_match, _ = exact_match(246 example.string_question, example.original_nc, number=True)247 if (not (pick_one(example.word_exact_match)) and not (248 pick_one(example.number_exact_match))):249 assert len(word_match) == 0250 assert len(number_match) == 0251 example.word_exact_match, word_match = partial_match(252 example.string_question, example.original_wc, number=False)253 #group by max254 example.word_group_by_max = group_by_max(example.original_wc, False)255 example.number_group_by_max = group_by_max(example.original_nc, True)256 #column name match257 example.word_column_exact_match, wcol_matched_indices = exact_column_match(258 example.string_question, example.original_wc_names, number=False)259 example.number_column_exact_match, ncol_matched_indices = exact_column_match(260 example.string_question, example.original_nc_names, number=False)261 if (not (1.0 in example.word_column_exact_match) and not (262 1.0 in example.number_column_exact_match)):263 example.word_column_exact_match = partial_column_match(264 example.string_question, example.original_wc_names, number=False)265 example.number_column_exact_match = partial_column_match(266 example.string_question, example.original_nc_names, number=False)267 if (len(word_match) > 0 or len(number_match) > 0):268 example.question.append(utility.entry_match_token)269 if (1.0 in example.word_column_exact_match or270 1.0 in example.number_column_exact_match):271 example.question.append(utility.column_match_token)272 example.string_question = example.question[:]273 example.number_lookup_matrix = np.transpose(274 example.number_lookup_matrix)[:]275 example.word_lookup_matrix = np.transpose(example.word_lookup_matrix)[:]276 example.columns = example.number_columns[:]277 example.word_columns = example.word_columns[:]278 example.len_total_cols = len(example.word_column_names) + len(279 example.number_column_names)280 example.column_names = example.number_column_names[:]281 example.word_column_names = example.word_column_names[:]282 example.string_column_names = example.number_column_names[:]283 example.string_word_column_names = example.word_column_names[:]284 example.sorted_number_index = []285 example.sorted_word_index = []286 example.column_mask = []287 example.word_column_mask = []288 example.processed_column_mask = []289 example.processed_word_column_mask = []290 example.word_column_entry_mask = []291 example.question_attention_mask = []292 example.question_number = example.question_number_1 = -1293 example.question_attention_mask = []294 example.ordinal_question = []295 example.ordinal_question_one = []296 new_question = []297 if (len(example.number_columns) > 0):298 example.len_col = len(example.number_columns[0])299 else:300 example.len_col = len(example.word_columns[0])301 for (start, length) in matched_indices:302 for j in range(length):303 example.question[start + j] = utility.unk_token304 #print example.question305 for word in example.question:306 if (isinstance(word, numbers.Number) or wiki_data.is_date(word)):307 if (not (isinstance(word, numbers.Number)) and308 wiki_data.is_date(word)):309 word = word.replace("X", "").replace("-", "")310 number_found += 1311 if (number_found == 1):312 example.question_number = word313 if (len(example.ordinal_question) > 0):314 example.ordinal_question[len(example.ordinal_question) - 1] = 1.0315 else:316 example.ordinal_question.append(1.0)317 elif (number_found == 2):318 example.question_number_1 = word319 if (len(example.ordinal_question_one) > 0):320 example.ordinal_question_one[len(example.ordinal_question_one) -321 1] = 1.0322 else:323 example.ordinal_question_one.append(1.0)324 else:325 new_question.append(word)326 example.ordinal_question.append(0.0)327 example.ordinal_question_one.append(0.0)328 example.question = [329 utility.word_ids[word_lookup(w, utility)] for w in new_question330 ]331 example.question_attention_mask = [0.0] * len(example.question)332 #when the first question number occurs before a word333 example.ordinal_question = example.ordinal_question[0:len(334 example.question)]335 example.ordinal_question_one = example.ordinal_question_one[0:len(336 example.question)]337 #question-padding338 example.question = [utility.word_ids[utility.dummy_token]] * (339 utility.FLAGS.question_length - len(example.question)340 ) + example.question341 example.question_attention_mask = [-10000.0] * (342 utility.FLAGS.question_length - len(example.question_attention_mask)343 ) + example.question_attention_mask344 example.ordinal_question = [0.0] * (utility.FLAGS.question_length -345 len(example.ordinal_question)346 ) + example.ordinal_question347 example.ordinal_question_one = [0.0] * (utility.FLAGS.question_length -348 len(example.ordinal_question_one)349 ) + example.ordinal_question_one350 if (True):351 #number columns and related-padding352 num_cols = len(example.columns)353 start = 0354 for column in example.number_columns:355 if (check_processed_cols(example.processed_number_columns[start],356 utility)):357 example.processed_column_mask.append(0.0)358 sorted_index = sorted(359 range(len(example.processed_number_columns[start])),360 key=lambda k: example.processed_number_columns[start][k],361 reverse=True)362 sorted_index = sorted_index + [utility.FLAGS.pad_int] * (363 utility.FLAGS.max_elements - len(sorted_index))364 example.sorted_number_index.append(sorted_index)365 example.columns[start] = column + [utility.FLAGS.pad_int] * (366 utility.FLAGS.max_elements - len(column))367 example.processed_number_columns[start] += [utility.FLAGS.pad_int] * (368 utility.FLAGS.max_elements -369 len(example.processed_number_columns[start]))370 start += 1371 example.column_mask.append(0.0)372 for remaining in range(num_cols, utility.FLAGS.max_number_cols):373 example.sorted_number_index.append([utility.FLAGS.pad_int] *374 (utility.FLAGS.max_elements))375 example.columns.append([utility.FLAGS.pad_int] *376 (utility.FLAGS.max_elements))377 example.processed_number_columns.append([utility.FLAGS.pad_int] *378 (utility.FLAGS.max_elements))379 example.number_exact_match.append([0.0] *380 (utility.FLAGS.max_elements))381 example.number_group_by_max.append([0.0] *382 (utility.FLAGS.max_elements))383 example.column_mask.append(-100000000.0)384 example.processed_column_mask.append(-100000000.0)385 example.number_column_exact_match.append(0.0)386 example.column_names.append([utility.dummy_token])387 #word column and related-padding388 start = 0389 word_num_cols = len(example.word_columns)390 for column in example.word_columns:391 if (check_processed_cols(example.processed_word_columns[start],392 utility)):393 example.processed_word_column_mask.append(0.0)394 sorted_index = sorted(395 range(len(example.processed_word_columns[start])),396 key=lambda k: example.processed_word_columns[start][k],397 reverse=True)398 sorted_index = sorted_index + [utility.FLAGS.pad_int] * (399 utility.FLAGS.max_elements - len(sorted_index))400 example.sorted_word_index.append(sorted_index)401 column = convert_to_int_2d_and_pad(column, utility)402 example.word_columns[start] = column + [[403 utility.word_ids[utility.dummy_token]404 ] * utility.FLAGS.max_entry_length] * (utility.FLAGS.max_elements -405 len(column))406 example.processed_word_columns[start] += [utility.FLAGS.pad_int] * (407 utility.FLAGS.max_elements -408 len(example.processed_word_columns[start]))409 example.word_column_entry_mask.append([0] * len(column) + [410 utility.word_ids[utility.dummy_token]411 ] * (utility.FLAGS.max_elements - len(column)))412 start += 1413 example.word_column_mask.append(0.0)414 for remaining in range(word_num_cols, utility.FLAGS.max_word_cols):415 example.sorted_word_index.append([utility.FLAGS.pad_int] *416 (utility.FLAGS.max_elements))417 example.word_columns.append([[utility.word_ids[utility.dummy_token]] *418 utility.FLAGS.max_entry_length] *419 (utility.FLAGS.max_elements))420 example.word_column_entry_mask.append(421 [utility.word_ids[utility.dummy_token]] *422 (utility.FLAGS.max_elements))423 example.word_exact_match.append([0.0] * (utility.FLAGS.max_elements))424 example.word_group_by_max.append([0.0] * (utility.FLAGS.max_elements))425 example.processed_word_columns.append([utility.FLAGS.pad_int] *426 (utility.FLAGS.max_elements))427 example.word_column_mask.append(-100000000.0)428 example.processed_word_column_mask.append(-100000000.0)429 example.word_column_exact_match.append(0.0)430 example.word_column_names.append([utility.dummy_token] *431 utility.FLAGS.max_entry_length)432 seen_tables[example.table_key] = 1433 #convert column and word column names to integers434 example.column_ids = convert_to_int_2d_and_pad(example.column_names,435 utility)436 example.word_column_ids = convert_to_int_2d_and_pad(437 example.word_column_names, utility)438 for i_em in range(len(example.number_exact_match)):439 example.number_exact_match[i_em] = example.number_exact_match[440 i_em] + [0.0] * (utility.FLAGS.max_elements -441 len(example.number_exact_match[i_em]))442 example.number_group_by_max[i_em] = example.number_group_by_max[443 i_em] + [0.0] * (utility.FLAGS.max_elements -444 len(example.number_group_by_max[i_em]))445 for i_em in range(len(example.word_exact_match)):446 example.word_exact_match[i_em] = example.word_exact_match[447 i_em] + [0.0] * (utility.FLAGS.max_elements -448 len(example.word_exact_match[i_em]))449 example.word_group_by_max[i_em] = example.word_group_by_max[450 i_em] + [0.0] * (utility.FLAGS.max_elements -451 len(example.word_group_by_max[i_em]))452 example.exact_match = example.number_exact_match + example.word_exact_match453 example.group_by_max = example.number_group_by_max + example.word_group_by_max454 example.exact_column_match = example.number_column_exact_match + example.word_column_exact_match455 #answer and related mask, padding456 if (example.is_lookup):457 example.answer = example.calc_answer458 example.number_print_answer = example.number_lookup_matrix.tolist()459 example.word_print_answer = example.word_lookup_matrix.tolist()460 for i_answer in range(len(example.number_print_answer)):461 example.number_print_answer[i_answer] = example.number_print_answer[462 i_answer] + [0.0] * (utility.FLAGS.max_elements -463 len(example.number_print_answer[i_answer]))464 for i_answer in range(len(example.word_print_answer)):465 example.word_print_answer[i_answer] = example.word_print_answer[466 i_answer] + [0.0] * (utility.FLAGS.max_elements -467 len(example.word_print_answer[i_answer]))468 example.number_lookup_matrix = convert_to_bool_and_pad(469 example.number_lookup_matrix, utility)470 example.word_lookup_matrix = convert_to_bool_and_pad(471 example.word_lookup_matrix, utility)472 for remaining in range(num_cols, utility.FLAGS.max_number_cols):473 example.number_lookup_matrix.append([False] *474 utility.FLAGS.max_elements)475 example.number_print_answer.append([0.0] * utility.FLAGS.max_elements)476 for remaining in range(word_num_cols, utility.FLAGS.max_word_cols):477 example.word_lookup_matrix.append([False] *478 utility.FLAGS.max_elements)479 example.word_print_answer.append([0.0] * utility.FLAGS.max_elements)480 example.print_answer = example.number_print_answer + example.word_print_answer481 else:482 example.answer = example.calc_answer483 example.print_answer = [[0.0] * (utility.FLAGS.max_elements)] * (484 utility.FLAGS.max_number_cols + utility.FLAGS.max_word_cols)485 #question_number masks486 if (example.question_number == -1):487 example.question_number_mask = np.zeros([utility.FLAGS.max_elements])488 else:489 example.question_number_mask = np.ones([utility.FLAGS.max_elements])490 if (example.question_number_1 == -1):491 example.question_number_one_mask = -10000.0492 else:493 example.question_number_one_mask = np.float64(0.0)494 if (example.len_col > utility.FLAGS.max_elements):495 continue496 processed_data.append(example)497 return processed_data498def add_special_words(utility):499 utility.words.append(utility.entry_match_token)500 utility.word_ids[utility.entry_match_token] = len(utility.word_ids)501 utility.reverse_word_ids[utility.word_ids[502 utility.entry_match_token]] = utility.entry_match_token503 utility.entry_match_token_id = utility.word_ids[utility.entry_match_token]504 print "entry match token: ", utility.word_ids[505 utility.entry_match_token], utility.entry_match_token_id506 utility.words.append(utility.column_match_token)507 utility.word_ids[utility.column_match_token] = len(utility.word_ids)508 utility.reverse_word_ids[utility.word_ids[509 utility.column_match_token]] = utility.column_match_token510 utility.column_match_token_id = utility.word_ids[utility.column_match_token]511 print "entry match token: ", utility.word_ids[512 utility.column_match_token], utility.column_match_token_id513 utility.words.append(utility.dummy_token)514 utility.word_ids[utility.dummy_token] = len(utility.word_ids)515 utility.reverse_word_ids[utility.word_ids[516 utility.dummy_token]] = utility.dummy_token517 utility.dummy_token_id = utility.word_ids[utility.dummy_token]518 utility.words.append(utility.unk_token)519 utility.word_ids[utility.unk_token] = len(utility.word_ids)520 utility.reverse_word_ids[utility.word_ids[521 utility.unk_token]] = utility.unk_token522def perform_word_cutoff(utility):523 if (utility.FLAGS.word_cutoff > 0):524 for word in utility.word_ids.keys():525 if (utility.word_count.has_key(word) and utility.word_count[word] <526 utility.FLAGS.word_cutoff and word != utility.unk_token and527 word != utility.dummy_token and word != utility.entry_match_token and528 word != utility.column_match_token):529 utility.word_ids.pop(word)530 utility.words.remove(word)531def word_dropout(question, utility):532 if (utility.FLAGS.word_dropout_prob > 0.0):533 new_question = []534 for i in range(len(question)):535 if (question[i] != utility.dummy_token_id and536 utility.random.random() > utility.FLAGS.word_dropout_prob):537 new_question.append(utility.word_ids[utility.unk_token])538 else:539 new_question.append(question[i])540 return new_question541 else:542 return question543def generate_feed_dict(data, curr, batch_size, gr, train=False, utility=None):544 #prepare feed dict dictionary545 feed_dict = {}546 feed_examples = []547 for j in range(batch_size):548 feed_examples.append(data[curr + j])549 if (train):550 feed_dict[gr.batch_question] = [551 word_dropout(feed_examples[j].question, utility)552 for j in range(batch_size)553 ]554 else:555 feed_dict[gr.batch_question] = [556 feed_examples[j].question for j in range(batch_size)557 ]558 feed_dict[gr.batch_question_attention_mask] = [559 feed_examples[j].question_attention_mask for j in range(batch_size)560 ]561 feed_dict[562 gr.batch_answer] = [feed_examples[j].answer for j in range(batch_size)]563 feed_dict[gr.batch_number_column] = [564 feed_examples[j].columns for j in range(batch_size)565 ]566 feed_dict[gr.batch_processed_number_column] = [567 feed_examples[j].processed_number_columns for j in range(batch_size)568 ]569 feed_dict[gr.batch_processed_sorted_index_number_column] = [570 feed_examples[j].sorted_number_index for j in range(batch_size)571 ]572 feed_dict[gr.batch_processed_sorted_index_word_column] = [573 feed_examples[j].sorted_word_index for j in range(batch_size)574 ]575 feed_dict[gr.batch_question_number] = np.array(576 [feed_examples[j].question_number for j in range(batch_size)]).reshape(577 (batch_size, 1))578 feed_dict[gr.batch_question_number_one] = np.array(579 [feed_examples[j].question_number_1 for j in range(batch_size)]).reshape(580 (batch_size, 1))581 feed_dict[gr.batch_question_number_mask] = [582 feed_examples[j].question_number_mask for j in range(batch_size)583 ]584 feed_dict[gr.batch_question_number_one_mask] = np.array(585 [feed_examples[j].question_number_one_mask for j in range(batch_size)586 ]).reshape((batch_size, 1))587 feed_dict[gr.batch_print_answer] = [588 feed_examples[j].print_answer for j in range(batch_size)589 ]590 feed_dict[gr.batch_exact_match] = [591 feed_examples[j].exact_match for j in range(batch_size)592 ]593 feed_dict[gr.batch_group_by_max] = [594 feed_examples[j].group_by_max for j in range(batch_size)595 ]596 feed_dict[gr.batch_column_exact_match] = [597 feed_examples[j].exact_column_match for j in range(batch_size)598 ]599 feed_dict[gr.batch_ordinal_question] = [600 feed_examples[j].ordinal_question for j in range(batch_size)601 ]602 feed_dict[gr.batch_ordinal_question_one] = [603 feed_examples[j].ordinal_question_one for j in range(batch_size)604 ]605 feed_dict[gr.batch_number_column_mask] = [606 feed_examples[j].column_mask for j in range(batch_size)607 ]608 feed_dict[gr.batch_number_column_names] = [609 feed_examples[j].column_ids for j in range(batch_size)610 ]611 feed_dict[gr.batch_processed_word_column] = [612 feed_examples[j].processed_word_columns for j in range(batch_size)613 ]614 feed_dict[gr.batch_word_column_mask] = [615 feed_examples[j].word_column_mask for j in range(batch_size)616 ]617 feed_dict[gr.batch_word_column_names] = [618 feed_examples[j].word_column_ids for j in range(batch_size)619 ]620 feed_dict[gr.batch_word_column_entry_mask] = [621 feed_examples[j].word_column_entry_mask for j in range(batch_size)622 ]...

Full Screen

Full Screen

media_sequence_util_test.py

Source:media_sequence_util_test.py Github

copy

Full Screen

1"""Copyright 2019 The MediaPipe Authors.2Licensed under the Apache License, Version 2.0 (the "License");3you may not use this file except in compliance with the License.4You may obtain a copy of the License at5 http://www.apache.org/licenses/LICENSE-2.06Unless required by applicable law or agreed to in writing, software7distributed under the License is distributed on an "AS IS" BASIS,8WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.9See the License for the specific language governing permissions and10limitations under the License.11Tests for media_sequence_util.py.12"""13from __future__ import absolute_import14from __future__ import division15from __future__ import print_function16import tensorflow.compat.v1 as tf17from mediapipe.util.sequence import media_sequence_util as msu18# run this code at the module level to procedurally define functions for test19# cases.20msu.create_bytes_context_feature(21 "string_context", "string_feature", module_dict=msu.__dict__)22msu.create_float_context_feature(23 "float_context", "float_feature", module_dict=msu.__dict__)24msu.create_int_context_feature(25 "int64_context", "int64_feature", module_dict=msu.__dict__)26msu.create_bytes_list_context_feature(27 "string_list_context", "string_vector_feature", module_dict=msu.__dict__)28msu.create_float_list_context_feature(29 "float_list_context", "float_vector_feature", module_dict=msu.__dict__)30msu.create_int_list_context_feature(31 "int64_list_context", "int64_vector_feature", module_dict=msu.__dict__)32msu.create_bytes_feature_list(33 "string_feature_list", "string_feature_list", module_dict=msu.__dict__)34msu.create_float_feature_list(35 "float_feature_list", "float_feature_list", module_dict=msu.__dict__)36msu.create_int_feature_list(37 "int64_feature_list", "int64_feature_list", module_dict=msu.__dict__)38msu.create_bytes_list_feature_list(39 "string_list_feature_list", "string_list_feature_list",40 module_dict=msu.__dict__)41msu.create_float_list_feature_list(42 "float_list_feature_list", "float_list_feature_list",43 module_dict=msu.__dict__)44msu.create_int_list_feature_list(45 "int64_list_feature_list", "int64_list_feature_list",46 module_dict=msu.__dict__)47class MediaSequenceTest(tf.test.TestCase):48 def test_set_context_float(self):49 example = tf.train.SequenceExample()50 key = "test_float"51 msu.set_context_float(key, 0.1, example)52 self.assertAlmostEqual(0.1,53 example.context.feature[key].float_list.value[0])54 def test_set_context_bytes(self):55 example = tf.train.SequenceExample()56 key = "test_string"57 msu.set_context_bytes(key, b"test", example)58 self.assertEqual(b"test",59 example.context.feature[key].bytes_list.value[0])60 def test_set_context_int(self):61 example = tf.train.SequenceExample()62 key = "test_int"63 msu.set_context_int(key, 47, example)64 self.assertEqual(47,65 example.context.feature[key].int64_list.value[0])66 def test_set_context_float_list(self):67 example = tf.train.SequenceExample()68 key = "test_float_list"69 msu.set_context_float_list(key, [0.0, 0.1], example)70 self.assertSequenceAlmostEqual(71 [0.0, 0.1], example.context.feature[key].float_list.value)72 def test_set_context_bytes_list(self):73 example = tf.train.SequenceExample()74 key = "test_string_list"75 msu.set_context_bytes_list(key, [b"test", b"test"], example)76 self.assertSequenceAlmostEqual(77 [b"test", b"test"], example.context.feature[key].bytes_list.value)78 def test_set_context_int_list(self):79 example = tf.train.SequenceExample()80 key = "test_int_list"81 msu.set_context_int_list(key, [0, 1], example)82 self.assertSequenceAlmostEqual(83 [0, 1], example.context.feature[key].int64_list.value)84 def test_round_trip_float_list_feature(self):85 example = tf.train.SequenceExample()86 key = "test_float_features"87 msu.add_float_list(key, [0.0, 0.1], example)88 msu.add_float_list(key, [0.1, 0.2], example)89 self.assertEqual(2, msu.get_feature_list_size(key, example))90 self.assertTrue(msu.has_feature_list(key, example))91 self.assertAllClose([0.0, 0.1], msu.get_float_list_at(key, 0, example))92 self.assertAllClose([0.1, 0.2], msu.get_float_list_at(key, 1, example))93 msu.clear_feature_list(key, example)94 self.assertEqual(0, msu.get_feature_list_size(key, example))95 self.assertFalse(msu.has_feature_list(key, example))96 def test_round_trip_bytes_list_feature(self):97 example = tf.train.SequenceExample()98 key = "test_bytes_features"99 msu.add_bytes_list(key, [b"test0", b"test1"], example)100 msu.add_bytes_list(key, [b"test1", b"test2"], example)101 self.assertEqual(2, msu.get_feature_list_size(key, example))102 self.assertTrue(msu.has_feature_list(key, example))103 self.assertAllEqual([b"test0", b"test1"],104 msu.get_bytes_list_at(key, 0, example))105 self.assertAllEqual([b"test1", b"test2"],106 msu.get_bytes_list_at(key, 1, example))107 msu.clear_feature_list(key, example)108 self.assertEqual(0, msu.get_feature_list_size(key, example))109 self.assertFalse(msu.has_feature_list(key, example))110 def test_round_trip_int_list_feature(self):111 example = tf.train.SequenceExample()112 key = "test_ints_features"113 msu.add_int_list(key, [0, 1], example)114 msu.add_int_list(key, [1, 2], example)115 self.assertEqual(2, msu.get_feature_list_size(key, example))116 self.assertTrue(msu.has_feature_list(key, example))117 self.assertAllClose([0, 1], msu.get_int_list_at(key, 0, example))118 self.assertAllClose([1, 2], msu.get_int_list_at(key, 1, example))119 msu.clear_feature_list(key, example)120 self.assertEqual(0, msu.get_feature_list_size(key, example))121 self.assertFalse(msu.has_feature_list(key, example))122 def test_round_trip_string_context(self):123 example = tf.train.SequenceExample()124 key = "string_feature"125 msu.set_string_context(b"test", example)126 self.assertEqual(b"test", msu.get_string_context(example))127 self.assertTrue(msu.has_string_context(example))128 self.assertEqual(b"test",129 example.context.feature[key].bytes_list.value[0])130 msu.clear_string_context(example)131 self.assertFalse(msu.has_string_context(example))132 self.assertEqual("string_feature", msu.get_string_context_key())133 def test_round_trip_float_context(self):134 example = tf.train.SequenceExample()135 key = "float_feature"136 msu.set_float_context(0.47, example)137 self.assertAlmostEqual(0.47, msu.get_float_context(example))138 self.assertTrue(msu.has_float_context(example))139 self.assertAlmostEqual(0.47,140 example.context.feature[key].float_list.value[0])141 msu.clear_float_context(example)142 self.assertFalse(msu.has_float_context(example))143 self.assertEqual("float_feature", msu.get_float_context_key())144 def test_round_trip_int_context(self):145 example = tf.train.SequenceExample()146 key = "int64_feature"147 msu.set_int64_context(47, example)148 self.assertEqual(47, msu.get_int64_context(example))149 self.assertTrue(msu.has_int64_context(example))150 self.assertEqual(47,151 example.context.feature[key].int64_list.value[0])152 msu.clear_int64_context(example)153 self.assertFalse(msu.has_int64_context(example))154 self.assertEqual("int64_feature", msu.get_int64_context_key())155 def test_round_trip_string_list_context(self):156 example = tf.train.SequenceExample()157 msu.set_string_list_context([b"test0", b"test1"], example)158 self.assertSequenceEqual([b"test0", b"test1"],159 msu.get_string_list_context(example))160 self.assertTrue(msu.has_string_list_context(example))161 msu.clear_string_list_context(example)162 self.assertFalse(msu.has_string_list_context(example))163 self.assertEqual("string_vector_feature",164 msu.get_string_list_context_key())165 def test_round_trip_float_list_context(self):166 example = tf.train.SequenceExample()167 msu.set_float_list_context([0.47, 0.49], example)168 self.assertSequenceAlmostEqual([0.47, 0.49],169 msu.get_float_list_context(example))170 self.assertTrue(msu.has_float_list_context(example))171 msu.clear_float_list_context(example)172 self.assertFalse(msu.has_float_list_context(example))173 self.assertEqual("float_vector_feature", msu.get_float_list_context_key())174 def test_round_trip_int_list_context(self):175 example = tf.train.SequenceExample()176 msu.set_int64_list_context([47, 49], example)177 self.assertSequenceEqual([47, 49], msu.get_int64_list_context(example))178 self.assertTrue(msu.has_int64_list_context(example))179 msu.clear_int64_list_context(example)180 self.assertFalse(msu.has_int64_list_context(example))181 self.assertEqual("int64_vector_feature", msu.get_int64_list_context_key())182 def test_round_trip_string_feature_list(self):183 example = tf.train.SequenceExample()184 msu.add_string_feature_list(b"test0", example)185 msu.add_string_feature_list(b"test1", example)186 self.assertEqual(b"test0", msu.get_string_feature_list_at(0, example))187 self.assertEqual(b"test1", msu.get_string_feature_list_at(1, example))188 self.assertTrue(msu.has_string_feature_list(example))189 self.assertEqual(2, msu.get_string_feature_list_size(example))190 msu.clear_string_feature_list(example)191 self.assertFalse(msu.has_string_feature_list(example))192 self.assertEqual(0, msu.get_string_feature_list_size(example))193 self.assertEqual("string_feature_list", msu.get_string_feature_list_key())194 def test_round_trip_float_feature_list(self):195 example = tf.train.SequenceExample()196 msu.add_float_feature_list(0.47, example)197 msu.add_float_feature_list(0.49, example)198 self.assertAlmostEqual(0.47, msu.get_float_feature_list_at(0, example))199 self.assertAlmostEqual(0.49, msu.get_float_feature_list_at(1, example))200 self.assertTrue(msu.has_float_feature_list(example))201 self.assertEqual(2, msu.get_float_feature_list_size(example))202 msu.clear_float_feature_list(example)203 self.assertFalse(msu.has_float_feature_list(example))204 self.assertEqual(0, msu.get_float_feature_list_size(example))205 self.assertEqual("float_feature_list", msu.get_float_feature_list_key())206 def test_round_trip_int_feature_list(self):207 example = tf.train.SequenceExample()208 msu.add_int64_feature_list(47, example)209 msu.add_int64_feature_list(49, example)210 self.assertEqual(47, msu.get_int64_feature_list_at(0, example))211 self.assertEqual(49, msu.get_int64_feature_list_at(1, example))212 self.assertTrue(msu.has_int64_feature_list(example))213 self.assertEqual(2, msu.get_int64_feature_list_size(example))214 msu.clear_int64_feature_list(example)215 self.assertFalse(msu.has_int64_feature_list(example))216 self.assertEqual(0, msu.get_int64_feature_list_size(example))217 self.assertEqual("int64_feature_list", msu.get_int64_feature_list_key())218 def test_round_trip_string_list_feature_list(self):219 example = tf.train.SequenceExample()220 msu.add_string_list_feature_list([b"test0", b"test1"], example)221 msu.add_string_list_feature_list([b"test1", b"test2"], example)222 self.assertSequenceEqual([b"test0", b"test1"],223 msu.get_string_list_feature_list_at(0, example))224 self.assertSequenceEqual([b"test1", b"test2"],225 msu.get_string_list_feature_list_at(1, example))226 self.assertTrue(msu.has_string_list_feature_list(example))227 self.assertEqual(2, msu.get_string_list_feature_list_size(example))228 msu.clear_string_list_feature_list(example)229 self.assertFalse(msu.has_string_list_feature_list(example))230 self.assertEqual(0, msu.get_string_list_feature_list_size(example))231 self.assertEqual("string_list_feature_list",232 msu.get_string_list_feature_list_key())233 def test_round_trip_float_list_feature_list(self):234 example = tf.train.SequenceExample()235 msu.add_float_list_feature_list([0.47, 0.49], example)236 msu.add_float_list_feature_list([0.49, 0.50], example)237 self.assertSequenceAlmostEqual(238 [0.47, 0.49], msu.get_float_list_feature_list_at(0, example))239 self.assertSequenceAlmostEqual(240 [0.49, 0.50], msu.get_float_list_feature_list_at(1, example))241 self.assertTrue(msu.has_float_list_feature_list(example))242 self.assertEqual(2, msu.get_float_list_feature_list_size(example))243 msu.clear_float_list_feature_list(example)244 self.assertFalse(msu.has_float_list_feature_list(example))245 self.assertEqual(0, msu.get_float_list_feature_list_size(example))246 self.assertEqual("float_list_feature_list",247 msu.get_float_list_feature_list_key())248 def test_round_trip_int_list_feature_list(self):249 example = tf.train.SequenceExample()250 msu.add_int64_list_feature_list([47, 49], example)251 msu.add_int64_list_feature_list([49, 50], example)252 self.assertSequenceEqual(253 [47, 49], msu.get_int64_list_feature_list_at(0, example))254 self.assertSequenceEqual(255 [49, 50], msu.get_int64_list_feature_list_at(1, example))256 self.assertTrue(msu.has_int64_list_feature_list(example))257 self.assertEqual(2, msu.get_int64_list_feature_list_size(example))258 msu.clear_int64_list_feature_list(example)259 self.assertFalse(msu.has_int64_list_feature_list(example))260 self.assertEqual(0, msu.get_int64_list_feature_list_size(example))261 self.assertEqual("int64_list_feature_list",262 msu.get_int64_list_feature_list_key())263 def test_prefix_int64_context(self):264 example = tf.train.SequenceExample()265 msu.set_int64_context(47, example, prefix="magic")266 self.assertFalse(msu.has_int64_context(example))267 self.assertTrue(msu.has_int64_context(example, prefix="magic"))268 self.assertEqual(47, msu.get_int64_context(example, prefix="magic"))269 def test_prefix_float_context(self):270 example = tf.train.SequenceExample()271 msu.set_float_context(47., example, prefix="magic")272 self.assertFalse(msu.has_float_context(example))273 self.assertTrue(msu.has_float_context(example, prefix="magic"))274 self.assertAlmostEqual(47., msu.get_float_context(example, prefix="magic"))275 def test_prefix_string_context(self):276 example = tf.train.SequenceExample()277 msu.set_string_context(b"47", example, prefix="magic")278 self.assertFalse(msu.has_string_context(example))279 self.assertTrue(msu.has_string_context(example, prefix="magic"))280 self.assertEqual(b"47", msu.get_string_context(example, prefix="magic"))281 def test_prefix_int64_list_context(self):282 example = tf.train.SequenceExample()283 msu.set_int64_list_context((47,), example, prefix="magic")284 self.assertFalse(msu.has_int64_list_context(example))285 self.assertTrue(msu.has_int64_list_context(example, prefix="magic"))286 self.assertEqual([47,], msu.get_int64_list_context(example, prefix="magic"))287 def test_prefix_float_list_context(self):288 example = tf.train.SequenceExample()289 msu.set_float_list_context((47.,), example, prefix="magic")290 self.assertFalse(msu.has_float_list_context(example))291 self.assertTrue(msu.has_float_list_context(example, prefix="magic"))292 self.assertAlmostEqual([47.,],293 msu.get_float_list_context(example, prefix="magic"))294 def test_prefix_string_list_context(self):295 example = tf.train.SequenceExample()296 msu.set_string_list_context((b"47",), example, prefix="magic")297 self.assertFalse(msu.has_string_list_context(example))298 self.assertTrue(msu.has_string_list_context(example, prefix="magic"))299 self.assertEqual([b"47",],300 msu.get_string_list_context(example, prefix="magic"))301 def test_prefix_int64_feature_list(self):302 example = tf.train.SequenceExample()303 msu.add_int64_feature_list(47, example, prefix="magic")304 self.assertFalse(msu.has_int64_feature_list(example))305 self.assertTrue(msu.has_int64_feature_list(example, prefix="magic"))306 self.assertEqual(47,307 msu.get_int64_feature_list_at(0, example, prefix="magic"))308 def test_prefix_float_feature_list(self):309 example = tf.train.SequenceExample()310 msu.add_float_feature_list(47., example, prefix="magic")311 self.assertFalse(msu.has_float_feature_list(example))312 self.assertTrue(msu.has_float_feature_list(example, prefix="magic"))313 self.assertAlmostEqual(314 47., msu.get_float_feature_list_at(0, example, prefix="magic"))315 def test_prefix_string_feature_list(self):316 example = tf.train.SequenceExample()317 msu.add_string_feature_list(b"47", example, prefix="magic")318 self.assertFalse(msu.has_string_feature_list(example))319 self.assertTrue(msu.has_string_feature_list(example, prefix="magic"))320 self.assertEqual(321 b"47", msu.get_string_feature_list_at(0, example, prefix="magic"))322 def test_prefix_int64_list_feature_list(self):323 example = tf.train.SequenceExample()324 msu.add_int64_list_feature_list((47,), example, prefix="magic")325 self.assertFalse(msu.has_int64_list_feature_list(example))326 self.assertTrue(msu.has_int64_list_feature_list(example, prefix="magic"))327 self.assertEqual(328 [47,], msu.get_int64_list_feature_list_at(0, example, prefix="magic"))329 def test_prefix_float_list_feature_list(self):330 example = tf.train.SequenceExample()331 msu.add_float_list_feature_list((47.,), example, prefix="magic")332 self.assertFalse(msu.has_float_list_feature_list(example))333 self.assertTrue(msu.has_float_list_feature_list(example, prefix="magic"))334 self.assertAlmostEqual(335 [47.,], msu.get_float_list_feature_list_at(0, example, prefix="magic"))336 def test_prefix_string_list_feature_list(self):337 example = tf.train.SequenceExample()338 msu.add_string_list_feature_list((b"47",), example, prefix="magic")339 self.assertFalse(msu.has_string_list_feature_list(example))340 self.assertTrue(msu.has_string_list_feature_list(example, prefix="magic"))341 self.assertEqual(342 [b"47",],343 msu.get_string_list_feature_list_at(0, example, prefix="magic"))344if __name__ == "__main__":...

Full Screen

Full Screen

media_sequence_test.py

Source:media_sequence_test.py Github

copy

Full Screen

1"""Copyright 2019 The MediaPipe Authors.2Licensed under the Apache License, Version 2.0 (the "License");3you may not use this file except in compliance with the License.4You may obtain a copy of the License at5 http://www.apache.org/licenses/LICENSE-2.06Unless required by applicable law or agreed to in writing, software7distributed under the License is distributed on an "AS IS" BASIS,8WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.9See the License for the specific language governing permissions and10limitations under the License.11Tests for media_sequence.py.12"""13from __future__ import absolute_import14from __future__ import division15from __future__ import print_function16import numpy as np17import tensorflow.compat.v1 as tf18from mediapipe.util.sequence import media_sequence as ms19class MediaSequenceTest(tf.test.TestCase):20 def test_expected_functions_are_defined(self):21 # The code from media_sequence_util is already tested, but this test ensures22 # that we actually generate the expected methods. We only test one per23 # feature and the only test is to not crash with undefined attributes. By24 # passing in a value, we also ensure that the types are correct because the25 # underlying code crashes with a type mismatch.26 example = tf.train.SequenceExample()27 # context28 ms.set_example_id(b"string", example)29 ms.set_example_dataset_name(b"string", example)30 ms.set_clip_media_id(b"string", example)31 ms.set_clip_alternative_media_id(b"string", example)32 ms.set_clip_encoded_media_bytes(b"string", example)33 ms.set_clip_encoded_media_start_timestamp(47, example)34 ms.set_clip_data_path(b"string", example)35 ms.set_clip_start_timestamp(47, example)36 ms.set_clip_end_timestamp(47, example)37 ms.set_clip_label_string((b"string", b"test"), example)38 ms.set_clip_label_index((47, 49), example)39 ms.set_clip_label_confidence((0.47, 0.49), example)40 ms.set_segment_start_timestamp((47, 49), example)41 ms.set_segment_start_index((47, 49), example)42 ms.set_segment_end_timestamp((47, 49), example)43 ms.set_segment_end_index((47, 49), example)44 ms.set_segment_label_index((47, 49), example)45 ms.set_segment_label_string((b"test", b"strings"), example)46 ms.set_segment_label_confidence((0.47, 0.49), example)47 ms.set_image_format(b"test", example)48 ms.set_image_channels(47, example)49 ms.set_image_colorspace(b"test", example)50 ms.set_image_height(47, example)51 ms.set_image_width(47, example)52 ms.set_image_frame_rate(0.47, example)53 ms.set_image_data_path(b"test", example)54 ms.set_forward_flow_format(b"test", example)55 ms.set_forward_flow_channels(47, example)56 ms.set_forward_flow_colorspace(b"test", example)57 ms.set_forward_flow_height(47, example)58 ms.set_forward_flow_width(47, example)59 ms.set_forward_flow_frame_rate(0.47, example)60 ms.set_class_segmentation_format(b"test", example)61 ms.set_class_segmentation_height(47, example)62 ms.set_class_segmentation_width(47, example)63 ms.set_class_segmentation_class_label_string((b"test", b"strings"), example)64 ms.set_class_segmentation_class_label_index((47, 49), example)65 ms.set_instance_segmentation_format(b"test", example)66 ms.set_instance_segmentation_height(47, example)67 ms.set_instance_segmentation_width(47, example)68 ms.set_instance_segmentation_object_class_index((47, 49), example)69 ms.set_bbox_parts((b"HEAD", b"TOE"), example)70 # feature lists71 ms.add_image_encoded(b"test", example)72 ms.add_image_multi_encoded([b"test", b"test"], example)73 ms.add_image_timestamp(47, example)74 ms.add_forward_flow_encoded(b"test", example)75 ms.add_forward_flow_multi_encoded([b"test", b"test"], example)76 ms.add_forward_flow_timestamp(47, example)77 ms.add_bbox_ymin((0.47, 0.49), example)78 ms.add_bbox_xmin((0.47, 0.49), example)79 ms.add_bbox_ymax((0.47, 0.49), example)80 ms.add_bbox_xmax((0.47, 0.49), example)81 ms.add_bbox_point_x((0.47, 0.49), example)82 ms.add_bbox_point_y((0.47, 0.49), example)83 ms.add_bbox_3d_point_x((0.47, 0.49), example)84 ms.add_bbox_3d_point_y((0.47, 0.49), example)85 ms.add_bbox_3d_point_z((0.47, 0.49), example)86 ms.add_predicted_bbox_ymin((0.47, 0.49), example)87 ms.add_predicted_bbox_xmin((0.47, 0.49), example)88 ms.add_predicted_bbox_ymax((0.47, 0.49), example)89 ms.add_predicted_bbox_xmax((0.47, 0.49), example)90 ms.add_bbox_num_regions(47, example)91 ms.add_bbox_is_annotated(47, example)92 ms.add_bbox_is_generated((47, 49), example)93 ms.add_bbox_is_occluded((47, 49), example)94 ms.add_bbox_label_index((47, 49), example)95 ms.add_bbox_label_string((b"test", b"strings"), example)96 ms.add_bbox_label_confidence((0.47, 0.49), example)97 ms.add_bbox_class_index((47, 49), example)98 ms.add_bbox_class_string((b"test", b"strings"), example)99 ms.add_bbox_class_confidence((0.47, 0.49), example)100 ms.add_bbox_track_index((47, 49), example)101 ms.add_bbox_track_string((b"test", b"strings"), example)102 ms.add_bbox_track_confidence((0.47, 0.49), example)103 ms.add_bbox_timestamp(47, example)104 ms.add_predicted_bbox_class_index((47, 49), example)105 ms.add_predicted_bbox_class_string((b"test", b"strings"), example)106 ms.add_predicted_bbox_timestamp(47, example)107 ms.add_class_segmentation_encoded(b"test", example)108 ms.add_class_segmentation_multi_encoded([b"test", b"test"], example)109 ms.add_instance_segmentation_encoded(b"test", example)110 ms.add_instance_segmentation_multi_encoded([b"test", b"test"], example)111 ms.add_class_segmentation_timestamp(47, example)112 ms.set_bbox_embedding_dimensions_per_region((47, 49), example)113 ms.set_bbox_embedding_format(b"test", example)114 ms.add_bbox_embedding_floats((0.47, 0.49), example)115 ms.add_bbox_embedding_encoded((b"text", b"stings"), example)116 ms.add_bbox_embedding_confidence((0.47, 0.49), example)117 ms.set_text_language(b"test", example)118 ms.set_text_context_content(b"text", example)119 ms.add_text_content(b"one", example)120 ms.add_text_timestamp(47, example)121 ms.add_text_confidence(0.47, example)122 ms.add_text_duration(47, example)123 ms.add_text_token_id(47, example)124 ms.add_text_embedding((0.47, 0.49), example)125 def test_bbox_round_trip(self):126 example = tf.train.SequenceExample()127 boxes = np.array([[0.1, 0.2, 0.3, 0.4],128 [0.5, 0.6, 0.7, 0.8]])129 empty_boxes = np.array([])130 ms.add_bbox(boxes, example)131 ms.add_bbox(empty_boxes, example)132 self.assertEqual(2, ms.get_bbox_size(example))133 self.assertAllClose(boxes, ms.get_bbox_at(0, example))134 self.assertTrue(ms.has_bbox(example))135 ms.clear_bbox(example)136 self.assertEqual(0, ms.get_bbox_size(example))137 def test_point_round_trip(self):138 example = tf.train.SequenceExample()139 points = np.array([[0.1, 0.2],140 [0.5, 0.6]])141 ms.add_bbox_point(points, example)142 ms.add_bbox_point(points, example)143 self.assertEqual(2, ms.get_bbox_point_size(example))144 self.assertAllClose(points, ms.get_bbox_point_at(0, example))145 self.assertTrue(ms.has_bbox_point(example))146 ms.clear_bbox_point(example)147 self.assertEqual(0, ms.get_bbox_point_size(example))148 def test_prefixed_point_round_trip(self):149 example = tf.train.SequenceExample()150 points = np.array([[0.1, 0.2],151 [0.5, 0.6]])152 ms.add_bbox_point(points, example, "test")153 ms.add_bbox_point(points, example, "test")154 self.assertEqual(2, ms.get_bbox_point_size(example, "test"))155 self.assertAllClose(points, ms.get_bbox_point_at(0, example, "test"))156 self.assertTrue(ms.has_bbox_point(example, "test"))157 ms.clear_bbox_point(example, "test")158 self.assertEqual(0, ms.get_bbox_point_size(example, "test"))159 def test_3d_point_round_trip(self):160 example = tf.train.SequenceExample()161 points = np.array([[0.1, 0.2, 0.3],162 [0.5, 0.6, 0.7]])163 ms.add_bbox_3d_point(points, example)164 ms.add_bbox_3d_point(points, example)165 self.assertEqual(2, ms.get_bbox_3d_point_size(example))166 self.assertAllClose(points, ms.get_bbox_3d_point_at(0, example))167 self.assertTrue(ms.has_bbox_3d_point(example))168 ms.clear_bbox_3d_point(example)169 self.assertEqual(0, ms.get_bbox_3d_point_size(example))170 def test_predicted_bbox_round_trip(self):171 example = tf.train.SequenceExample()172 boxes = np.array([[0.1, 0.2, 0.3, 0.4],173 [0.5, 0.6, 0.7, 0.8]])174 ms.add_predicted_bbox(boxes, example)175 ms.add_predicted_bbox(boxes, example)176 self.assertEqual(2, ms.get_predicted_bbox_size(example))177 self.assertAllClose(boxes, ms.get_predicted_bbox_at(0, example))178 self.assertTrue(ms.has_predicted_bbox(example))179 ms.clear_predicted_bbox(example)180 self.assertEqual(0, ms.get_predicted_bbox_size(example))181 def test_float_list_round_trip(self):182 example = tf.train.SequenceExample()183 values_1 = [0.1, 0.2, 0.3]184 values_2 = [0.2, 0.3, 0.4]185 ms.add_feature_floats(values_1, example, "1")186 ms.add_feature_floats(values_1, example, "1")187 ms.add_feature_floats(values_2, example, "2")188 self.assertEqual(2, ms.get_feature_floats_size(example, "1"))189 self.assertEqual(1, ms.get_feature_floats_size(example, "2"))190 self.assertTrue(ms.has_feature_floats(example, "1"))191 self.assertTrue(ms.has_feature_floats(example, "2"))192 self.assertAllClose(values_1, ms.get_feature_floats_at(0, example, "1"))193 self.assertAllClose(values_2, ms.get_feature_floats_at(0, example, "2"))194 ms.clear_feature_floats(example, "1")195 self.assertEqual(0, ms.get_feature_floats_size(example, "1"))196 self.assertFalse(ms.has_feature_floats(example, "1"))197 self.assertEqual(1, ms.get_feature_floats_size(example, "2"))198 self.assertTrue(ms.has_feature_floats(example, "2"))199 ms.clear_feature_floats(example, "2")200 self.assertEqual(0, ms.get_feature_floats_size(example, "2"))201 self.assertFalse(ms.has_feature_floats(example, "2"))202 def test_feature_timestamp_round_trip(self):203 example = tf.train.SequenceExample()204 values_1 = 47205 values_2 = 49206 ms.add_feature_timestamp(values_1, example, "1")207 ms.add_feature_timestamp(values_1, example, "1")208 ms.add_feature_timestamp(values_2, example, "2")209 self.assertEqual(2, ms.get_feature_timestamp_size(example, "1"))210 self.assertEqual(1, ms.get_feature_timestamp_size(example, "2"))211 self.assertTrue(ms.has_feature_timestamp(example, "1"))212 self.assertTrue(ms.has_feature_timestamp(example, "2"))213 self.assertAllClose(values_1,214 ms.get_feature_timestamp_at(0, example, "1"))215 self.assertAllClose(values_2,216 ms.get_feature_timestamp_at(0, example, "2"))217 ms.clear_feature_timestamp(example, "1")218 self.assertEqual(0, ms.get_feature_timestamp_size(example, "1"))219 self.assertFalse(ms.has_feature_timestamp(example, "1"))220 self.assertEqual(1, ms.get_feature_timestamp_size(example, "2"))221 self.assertTrue(ms.has_feature_timestamp(example, "2"))222 ms.clear_feature_timestamp(example, "2")223 self.assertEqual(0, ms.get_feature_timestamp_size(example, "2"))224 self.assertFalse(ms.has_feature_timestamp(example, "2"))225 def test_feature_dimensions_round_trip(self):226 example = tf.train.SequenceExample()227 ms.set_feature_dimensions([47, 49], example, "1")228 ms.set_feature_dimensions([49, 50], example, "2")229 self.assertSequenceEqual([47, 49],230 ms.get_feature_dimensions(example, "1"))231 self.assertSequenceEqual([49, 50],232 ms.get_feature_dimensions(example, "2"))233 self.assertTrue(ms.has_feature_dimensions(example, "1"))234 self.assertTrue(ms.has_feature_dimensions(example, "2"))235 ms.clear_feature_dimensions(example, "1")236 self.assertFalse(ms.has_feature_dimensions(example, "1"))237 self.assertTrue(ms.has_feature_dimensions(example, "2"))238 ms.clear_feature_dimensions(example, "2")239 self.assertFalse(ms.has_feature_dimensions(example, "1"))240 self.assertFalse(ms.has_feature_dimensions(example, "2"))241if __name__ == "__main__":...

Full Screen

Full Screen

RNTesterList.ios.js

Source:RNTesterList.ios.js Github

copy

Full Screen

1/**2 * Copyright (c) Meta Platforms, Inc. and affiliates.3 *4 * This source code is licensed under the MIT license found in the5 * LICENSE file in the root directory of this source tree.6 *7 * @format8 * @flow9 */10'use strict';11import type {RNTesterModuleInfo} from '../types/RNTesterTypes';12const Components: Array<RNTesterModuleInfo> = [13 {14 key: 'ActivityIndicatorExample',15 category: 'UI',16 module: require('../examples/ActivityIndicator/ActivityIndicatorExample'),17 supportsTVOS: true,18 },19 {20 key: 'ButtonExample',21 module: require('../examples/Button/ButtonExample'),22 category: 'UI',23 supportsTVOS: true,24 },25 {26 key: 'FlatListExampleIndex',27 module: require('../examples/FlatList/FlatListExampleIndex').default,28 category: 'ListView',29 supportsTVOS: true,30 },31 {32 key: 'ImageExample',33 module: require('../examples/Image/ImageExample'),34 category: 'Basic',35 supportsTVOS: true,36 },37 {38 key: 'JSResponderHandlerExample',39 module: require('../examples/JSResponderHandlerExample/JSResponderHandlerExample'),40 },41 {42 key: 'InputAccessoryViewExample',43 module: require('../examples/InputAccessoryView/InputAccessoryViewExample'),44 supportsTVOS: false,45 },46 {47 key: 'KeyboardAvoidingViewExample',48 module: require('../examples/KeyboardAvoidingView/KeyboardAvoidingViewExample'),49 supportsTVOS: false,50 },51 {52 key: 'LayoutEventsExample',53 module: require('../examples/Layout/LayoutEventsExample'),54 supportsTVOS: true,55 },56 {57 key: 'ModalExample',58 module: require('../examples/Modal/ModalExample'),59 supportsTVOS: true,60 },61 {62 key: 'NewAppScreenExample',63 module: require('../examples/NewAppScreen/NewAppScreenExample'),64 supportsTVOS: false,65 },66 {67 key: 'PressableExample',68 module: require('../examples/Pressable/PressableExample'),69 supportsTVOS: true,70 },71 {72 key: 'RefreshControlExample',73 module: require('../examples/RefreshControl/RefreshControlExample'),74 supportsTVOS: false,75 },76 {77 key: 'ScrollViewSimpleExample',78 module: require('../examples/ScrollView/ScrollViewSimpleExample'),79 category: 'Basic',80 supportsTVOS: true,81 },82 {83 key: 'SafeAreaViewExample',84 module: require('../examples/SafeAreaView/SafeAreaViewExample'),85 supportsTVOS: false,86 },87 {88 key: 'ScrollViewExample',89 module: require('../examples/ScrollView/ScrollViewExample'),90 category: 'Basic',91 supportsTVOS: true,92 },93 {94 key: 'ScrollViewAnimatedExample',95 module: require('../examples/ScrollView/ScrollViewAnimatedExample'),96 supportsTVOS: true,97 },98 {99 key: 'ScrollViewIndicatorInsetsExample',100 module: require('../examples/ScrollView/ScrollViewIndicatorInsetsExample'),101 supportsTVOS: true,102 },103 {104 key: 'SectionListIndex',105 module: require('../examples/SectionList/SectionListIndex'),106 supportsTVOS: true,107 },108 {109 key: 'TVTextScrollViewExample',110 module: require('../examples/TVTextScrollView/TVTextScrollViewExample'),111 supportsTVOS: true,112 },113 {114 key: 'StatusBarExample',115 module: require('../examples/StatusBar/StatusBarExample'),116 supportsTVOS: false,117 },118 {119 key: 'SwipeableCardExample',120 module: require('../examples/SwipeableCardExample/SwipeableCardExample'),121 category: 'UI',122 supportsTVOS: false,123 },124 {125 key: 'SwitchExample',126 module: require('../examples/Switch/SwitchExample'),127 category: 'UI',128 supportsTVOS: false,129 },130 {131 key: 'TextExample',132 module: require('../examples/Text/TextExample.ios'),133 category: 'Basic',134 supportsTVOS: true,135 },136 {137 key: 'TextInputExample',138 module: require('../examples/TextInput/TextInputExample'),139 category: 'Basic',140 supportsTVOS: true,141 },142 {143 key: 'TouchableExample',144 module: require('../examples/Touchable/TouchableExample'),145 supportsTVOS: true,146 },147 {148 key: 'TransparentHitTestExample',149 module: require('../examples/TransparentHitTest/TransparentHitTestExample'),150 supportsTVOS: false,151 },152 {153 key: 'ViewExample',154 module: require('../examples/View/ViewExample'),155 category: 'Basic',156 supportsTVOS: true,157 },158 {159 key: 'NewArchitectureExample',160 category: 'UI',161 module: require('../examples/NewArchitecture/NewArchitectureExample'),162 supportsTVOS: false,163 },164];165const APIs: Array<RNTesterModuleInfo> = [166 {167 key: 'AccessibilityExample',168 module: require('../examples/Accessibility/AccessibilityExample'),169 supportsTVOS: false,170 },171 {172 key: 'AccessibilityIOSExample',173 module: require('../examples/Accessibility/AccessibilityIOSExample'),174 category: 'iOS',175 supportsTVOS: false,176 },177 {178 key: 'ActionSheetIOSExample',179 module: require('../examples/ActionSheetIOS/ActionSheetIOSExample'),180 category: 'iOS',181 supportsTVOS: true,182 },183 {184 key: 'AlertIOSExample',185 module: require('../examples/Alert/AlertIOSExample'),186 category: 'iOS',187 supportsTVOS: true,188 },189 {190 key: 'AnimatedIndex',191 module: require('../examples/Animated/AnimatedIndex').default,192 supportsTVOS: true,193 },194 {195 key: 'AnExApp',196 module: require('../examples/AnimatedGratuitousApp/AnExApp'),197 supportsTVOS: true,198 },199 {200 key: 'AppearanceExample',201 module: require('../examples/Appearance/AppearanceExample'),202 supportsTVOS: false,203 },204 {205 key: 'AppStateExample',206 module: require('../examples/AppState/AppStateExample'),207 supportsTVOS: true,208 },209 {210 key: 'BorderExample',211 module: require('../examples/Border/BorderExample'),212 supportsTVOS: true,213 },214 {215 key: 'BoxShadowExample',216 module: require('../examples/BoxShadow/BoxShadowExample'),217 supportsTVOS: true,218 },219 {220 key: 'CrashExample',221 module: require('../examples/Crash/CrashExample'),222 supportsTVOS: false,223 },224 {225 key: 'DevSettings',226 module: require('../examples/DevSettings/DevSettingsExample'),227 },228 {229 key: 'Dimensions',230 module: require('../examples/Dimensions/DimensionsExample'),231 supportsTVOS: true,232 },233 {234 key: 'LayoutAnimationExample',235 module: require('../examples/Layout/LayoutAnimationExample'),236 supportsTVOS: true,237 },238 {239 key: 'LayoutExample',240 module: require('../examples/Layout/LayoutExample'),241 supportsTVOS: true,242 },243 {244 key: 'LinkingExample',245 module: require('../examples/Linking/LinkingExample'),246 supportsTVOS: true,247 },248 {249 key: 'NativeAnimationsExample',250 module: require('../examples/NativeAnimation/NativeAnimationsExample'),251 supportsTVOS: true,252 },253 {254 key: 'OrientationChangeExample',255 module: require('../examples/OrientationChange/OrientationChangeExample'),256 supportsTVOS: false,257 },258 {259 key: 'PanResponderExample',260 module: require('../examples/PanResponder/PanResponderExample'),261 supportsTVOS: false,262 },263 {264 key: 'PlatformColorExample',265 module: require('../examples/PlatformColor/PlatformColorExample'),266 supportsTVOS: true,267 },268 {269 key: 'PointerEventsExample',270 module: require('../examples/PointerEvents/PointerEventsExample'),271 supportsTVOS: false,272 },273 {274 key: 'RCTRootViewIOSExample',275 module: require('../examples/RCTRootView/RCTRootViewIOSExample'),276 supportsTVOS: true,277 },278 {279 key: 'RTLExample',280 module: require('../examples/RTL/RTLExample'),281 supportsTVOS: true,282 },283 {284 key: 'ShareExample',285 module: require('../examples/Share/ShareExample'),286 supportsTVOS: true,287 },288 {289 key: 'SnapshotExample',290 module: require('../examples/Snapshot/SnapshotExample'),291 supportsTVOS: true,292 },293 {294 key: 'TimerExample',295 module: require('../examples/Timer/TimerExample'),296 supportsTVOS: true,297 },298 {299 key: 'TransformExample',300 module: require('../examples/Transform/TransformExample'),301 supportsTVOS: true,302 },303 {304 key: 'TVEventHandlerExample',305 category: 'TV',306 module: require('../examples/TVEventHandler/TVEventHandlerExample'),307 supportsTVOS: true,308 },309 {310 key: 'TVDirectionalNextFocusExample',311 category: 'TV',312 module: require('../examples/DirectionalNextFocus/DirectionalNextFocusExample'),313 supportsTVOS: true,314 },315 {316 key: 'TVFocusGuideExample',317 category: 'TV',318 module: require('../examples/TVFocusGuide/TVFocusGuideExample'),319 supportsTVOS: true,320 },321 {322 key: 'TVFocusGuideSafePaddingExample',323 category: 'TV',324 module: require('../examples/TVFocusGuide/TVFocusGuideSafePaddingExample'),325 supportsTVOS: true,326 },327 {328 key: 'TurboModuleExample',329 module: require('../examples/TurboModule/TurboModuleExample'),330 supportsTVOS: false,331 },332 {333 key: 'VibrationExample',334 module: require('../examples/Vibration/VibrationExample'),335 supportsTVOS: false,336 },337 {338 key: 'WebSocketExample',339 module: require('../examples/WebSocket/WebSocketExample'),340 supportsTVOS: true,341 },342 {343 key: 'XHRExample',344 module: require('../examples/XHR/XHRExample'),345 supportsTVOS: true,346 },347];348const Modules: {...} = {};349APIs.concat(Components).forEach(Example => {350 Modules[Example.key] = Example.module;351});352const RNTesterList = {353 APIs,354 Components,355 Modules,356};...

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 pandera 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