How to use test_window_size method in Airtest

Best Python code snippet using Airtest

main.py

Source:main.py Github

copy

Full Screen

1# copyright (c) 2020 PaddlePaddle Authors. All Rights Reserve.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.14import paddle15import argparse16from paddlevideo.utils import get_config17from paddlevideo.tasks import train_model, train_model_multigrid, test_model, train_dali18from paddlevideo.utils import get_dist_info19import numpy as np20import random21from paddlevideo.modeling.backbones.effigcn_init import EffigcnInit22def predefined_model_list():23 agcn_model_list = [24 {'cfg_path': 'configs/recognition/agcn_fold/agcn_fsd0.yaml',25 'weight_path': './output/AGCN_fold0/AGCN_best.pdparams',26 'test_window_size': [300, 350, 500]},27 {'cfg_path': 'configs/recognition/agcn_fold/agcn_fsd1.yaml',28 'weight_path': './output/AGCN_fold1/AGCN_best.pdparams',29 'test_window_size': [300, 350, 500]},30 {'cfg_path': 'configs/recognition/agcn_fold/agcn_fsd2.yaml',31 'weight_path': './output/AGCN_fold2/AGCN_best.pdparams',32 'test_window_size': [300, 350, 500]},33 {'cfg_path': 'configs/recognition/agcn_fold/agcn_fsd3.yaml',34 'weight_path': './output/AGCN_fold3/AGCN_best.pdparams',35 'test_window_size': [300, 350, 500]},36 {'cfg_path': 'configs/recognition/agcn_fold/agcn_fsd4.yaml',37 'weight_path': './output/AGCN_fold4/AGCN_best.pdparams',38 'test_window_size': [300, 350, 500]}39 ]40 ctrgcn_model_list = [41 {'cfg_path': 'configs/recognition/ctrgcn_fold/ctrgcn_fsd0.yaml',42 'weight_path': './output/CTRGCN_fold0/CTRGCN_best.pdparams',43 'test_window_size': [300, 350, 450]},44 {'cfg_path': 'configs/recognition/ctrgcn_fold/ctrgcn_fsd1.yaml',45 'weight_path': './output/CTRGCN_fold1/CTRGCN_best.pdparams',46 'test_window_size': [300, 350, 450]},47 {'cfg_path': 'configs/recognition/ctrgcn_fold/ctrgcn_fsd2.yaml',48 'weight_path': './output/CTRGCN_fold2/CTRGCN_best.pdparams',49 'test_window_size': [300, 350, 450]},50 {'cfg_path': 'configs/recognition/ctrgcn_fold/ctrgcn_fsd3.yaml',51 'weight_path': './output/CTRGCN_fold3/CTRGCN_best.pdparams',52 'test_window_size': [300, 350, 450]},53 {'cfg_path': 'configs/recognition/ctrgcn_fold/ctrgcn_fsd4.yaml',54 'weight_path': './output/CTRGCN_fold4/CTRGCN_best.pdparams',55 'test_window_size': [300, 350, 450]}56 ]57 ctrgcn2_model_list = [58 {'cfg_path': 'configs/recognition/ctrgcn2_fold/ctrgcn_fsd0.yaml',59 'weight_path': './output/CTRGCN2_fold0/CTRGCN_best.pdparams',60 'test_window_size': [350]},61 {'cfg_path': 'configs/recognition/ctrgcn2_fold/ctrgcn_fsd1.yaml',62 'weight_path': './output/CTRGCN2_fold1/CTRGCN_best.pdparams',63 'test_window_size': [350]},64 {'cfg_path': 'configs/recognition/ctrgcn2_fold/ctrgcn_fsd2.yaml',65 'weight_path': './output/CTRGCN2_fold2/CTRGCN_best.pdparams',66 'test_window_size': [350]},67 {'cfg_path': 'configs/recognition/ctrgcn2_fold/ctrgcn_fsd3.yaml',68 'weight_path': './output/CTRGCN2_fold3/CTRGCN_best.pdparams',69 'test_window_size': [350]},70 {'cfg_path': 'configs/recognition/ctrgcn2_fold/ctrgcn_fsd4.yaml',71 'weight_path': './output/CTRGCN2_fold4/CTRGCN_best.pdparams',72 'test_window_size': [350]}73 ]74 stgcn_model_list = [75 {'cfg_path': 'configs/recognition/stgcn_fold/stgcn_fsd0.yaml',76 'weight_path': './output/STGCN_fold0/STGCN_best.pdparams',77 'test_window_size': [350]},78 {'cfg_path': 'configs/recognition/stgcn_fold/stgcn_fsd1.yaml',79 'weight_path': './output/STGCN_fold1/STGCN_best.pdparams',80 'test_window_size': [350]},81 {'cfg_path': 'configs/recognition/stgcn_fold/stgcn_fsd2.yaml',82 'weight_path': './output/STGCN_fold2/STGCN_best.pdparams',83 'test_window_size': [350]},84 {'cfg_path': 'configs/recognition/stgcn_fold/stgcn_fsd3.yaml',85 'weight_path': './output/STGCN_fold3/STGCN_best.pdparams',86 'test_window_size': [350]},87 {'cfg_path': 'configs/recognition/stgcn_fold/stgcn_fsd4.yaml',88 'weight_path': './output/STGCN_fold4/STGCN_best.pdparams',89 'test_window_size': [350]},90 ]91 effigcn_model_list = [92 {'cfg_path': 'configs/recognition/effigcn_fold/effigcn_fsd0.yaml',93 'weight_path': './output/EFFGCN_fold0/EFFGCN_best.pdparams',94 'test_window_size': [500]},95 {'cfg_path': 'configs/recognition/effigcn_fold/effigcn_fsd1.yaml',96 'weight_path': './output/EFFGCN_fold1/EFFGCN_best.pdparams',97 'test_window_size': [500]},98 {'cfg_path': 'configs/recognition/effigcn_fold/effigcn_fsd2.yaml',99 'weight_path': './output/EFFGCN_fold2/EFFGCN_best.pdparams',100 'test_window_size': [500]},101 {'cfg_path': 'configs/recognition/effigcn_fold/effigcn_fsd3.yaml',102 'weight_path': './output/EFFGCN_fold3/EFFGCN_best.pdparams',103 'test_window_size': [500]},104 {'cfg_path': 'configs/recognition/effigcn_fold/effigcn_fsd4.yaml',105 'weight_path': './output/EFFGCN_fold4/EFFGCN_best.pdparams',106 'test_window_size': [500]},107 ]108 models = agcn_model_list + ctrgcn_model_list + ctrgcn2_model_list + stgcn_model_list + effigcn_model_list109 return models110def parse_args():111 parser = argparse.ArgumentParser("PaddleVideo train script")112 # parser.add_argument('-c',113 # '--config',114 # type=str,115 # default='configs/example.yaml',116 # help='config file path')117 parser.add_argument('-o',118 '--override',119 action='append',120 default=[],121 help='config options to be overridden')122 parser.add_argument('--test',123 action='store_true',124 help='whether to test a model')125 parser.add_argument('--train_dali',126 action='store_true',127 help='whether to use dali to speed up training')128 parser.add_argument('--multigrid',129 action='store_true',130 help='whether to use multigrid training')131 parser.add_argument('-w',132 '--weights',133 type=str,134 help='weights for finetuning or testing')135 parser.add_argument('--fleet',136 action='store_true',137 help='whether to use fleet run distributed training')138 parser.add_argument('--amp',139 action='store_true',140 help='whether to open amp training.')141 parser.add_argument(142 '--validate',143 action='store_true',144 help='whether to evaluate the checkpoint during training')145 parser.add_argument('-g', '--gpu', default="0", type=str)146 args = parser.parse_args()147 return args148def main():149 args = parse_args()150 # cfg = get_config(args.config, overrides=args.override)151 _, world_size = get_dist_info()152 parallel = world_size != 1153 if parallel:154 paddle.distributed.init_parallel_env()155 model_list = predefined_model_list()156 print("************************************************************")157 for model in model_list:158 print(model['cfg_path'])159 print("************************************************************")160 for model in model_list:161 np.random.seed(42)162 random.seed(2021)163 paddle.seed(102)164 cfg = get_config(model['cfg_path'], overrides=args.override)165 cfg['gpu'] = args.gpu166 print("*************" + model['cfg_path'] + "*******************")167 if (cfg.MODEL.backbone.name == 'EfficientGCN'):168 EffigcnInit(cfg) # 初始化EfficientGCN参数169 if args.test:170 test_model(cfg, weights=model['weight_path'], parallel=parallel, test_window_size=model['test_window_size'])171 else:172 train_model(cfg, weights=args.weights, parallel=parallel, validate=args.validate, use_fleet=args.fleet,173 amp=args.amp)174 # if args.test:175 # test_model(cfg, weights=args.weights, parallel=parallel)176 # elif args.train_dali:177 #178 # train_dali(cfg, weights=args.weights, parallel=parallel)179 # elif args.multigrid:180 # train_model_multigrid(cfg, world_size, validate=args.validate)181 # else:182 # train_model(cfg,183 # weights=args.weights,184 # parallel=parallel,185 # validate=args.validate,186 # use_fleet=args.fleet,187 # amp=args.amp)188if __name__ == '__main__':...

Full Screen

Full Screen

nightly_torch.py

Source:nightly_torch.py Github

copy

Full Screen

1import sys2import time3#sys.path.append('../gpt-2/src/')4#import callable_gpt2 as gpt25#import model6#import encoder7#import sample8import torch9import numpy as np10import pandas as pd11from transformers import *12#tf.keras.backend.set_floatx('float64')13'''14error in tensorflow dtype init if tensorflow version = 2.0.0beta115pip uninstall tensorflow 16pip install tensorflow==2.0.017unhashable18tf.compat.v1.enable_tensor_equality()19'''20train_window_size = 40021test_window_size = 10022def pad_corpus_ori(sentences, pad_token, window_size):23 pad_sentences = []24 i = 025 for text in sentences:26 text = text.split()27 extended_text = text[:window_size-1] + [pad_token] * (window_size - len(text)-1)28 29 pad_sentences.append(extended_text)30 i += 131 return pad_sentences32def pad_corpus(sentences, start_token, end_token, pad_token, window_size):33 pad_sentences = []34 i = 035 for text in sentences:36 text = text.split()37 extended_text = text[:window_size-1] + [pad_token] * (window_size - len(text)-1) + [end_token]38 39 pad_sentences.append(extended_text)40 i += 141 return pad_sentences42def pad_corpus_simul(train_sentences, test_sentences, special_tokens, train_window_size, test_window_size):43 pad_sentences = []44 i = 045 for train_text, test_text in zip(train_sentences, test_sentences):46 train_text, test_text = train_text.split(), test_text.split()47 extended_text = [special_tokens['bos_token']] + train_text[:train_window_size-1] + [special_tokens['pad_token']] * (train_window_size - len(train_text)-1) + [special_tokens['cls_token']] + \48 test_text[:test_window_size-1] + [special_tokens['pad_token']] * (test_window_size - len(test_text)-1) + [special_tokens['eos_token']]49 50 pad_sentences.append(extended_text)51 i += 152 #print("length of post-padded text", len(pad_sentences[0]))53 return pad_sentences54def train(model, tokenizer, file_path, special_tokens):55 optimizer = AdamW(model.parameters())56 57 batch_size = 1058 reader = pd.read_json(file_path, precise_float=True, dtype=False, lines=True, chunksize=batch_size)59 train_steps = 060 step_start_time = time.time()61 training_time = [step_start_time]62 63 for section in reader:64 #print("section['normalizedBody']: \n", section['normalizedBody'].tolist(), len(section['normalizedBody'].tolist()))65 train_steps += 166 67 # get paragraph and summary68 train_words = section['normalizedBody'].tolist()69 test_words = section['summary'].tolist()70 #words = np.array(words)71 #print("words as numpy\n", words, "\n", words.shape)72 #print("concatted words", words)73 words = pad_corpus_simul(train_words, test_words, special_tokens, train_window_size, test_window_size)74 #test_words = pad_corpus(test_words, special_tokens['bos_token'], special_tokens['eos_token'], special_tokens['pad_token'], test_window_size)75 #train_words = pad_corpus_ori(train_words, special_tokens['pad_token'], train_window_size)76 #test_words = pad_corpus_ori(test_words, special_tokens['pad_token'], test_window_size)77 '''78 train_words = pad_corpus_ori(train_words, '', train_window_size)79 words = []80 for train, test in zip(train_words, test_words):81 words.append(train + test)82 '''83 words = [ tokenizer.encode(text) for text in words ]84 words = torch.tensor(words)85 test_words = pad_corpus_ori(test_words, special_tokens['pad_token'], test_window_size)86 test_words = [ tokenizer.encode(text) for text in test_words ]87 test_words = torch.tensor(test_words)88 #words = tf.reshape(words, [batch_size, -1])89 print("words as tensor\n", words, "\n", words.shape)90 91 outputs = model(words, labels=words) # last hidden states92 loss, logits = outputs[0], outputs[1]93 #logit = logit.numpy()94 predicted_index = torch.argmax(logits[0, -1, :])95 #loss = torch.keras.losses.sparse_categorical_crossentropy(words, logits, from_logits=True)96 #print("loss\n", loss, "\n", loss.shape)97 print("probs first\n", logits.shape)98 print("encoded prediction", predicted_index)99 print("decoded sentence first\n", tokenizer.decode(predicted_index))100 exit(0)101if __name__ == '__main__':102 # convert to pretrained to use transformers103 104 tokenizer = GPT2Tokenizer.from_pretrained('gpt2')105 model = GPT2LMHeadModel.from_pretrained('gpt2')106 #print("loaded model", model)107 #add the special tokens into the vocabulary108 special_tokens = {'bos_token': '<bos>', 'cls_token': '<cls>', 'eos_token': '<eos>',109 'pad_token': '<pad>'}110 # tf transformers module not currently implemented resize_token_embeddings function :(111 tokenizer.add_special_tokens(special_tokens)112 model.resize_token_embeddings(len(tokenizer))113 114 #num_train_optimization_steps = len(self.train_dataset) * options['num_epochs'] // options['train_batchsize']115 #train(model, '../data/tldr_train80.jsonl', special_tokens)116 train(model, tokenizer, '../data/tldr-training-data.jsonl', special_tokens)...

Full Screen

Full Screen

out_score.py

Source:out_score.py Github

copy

Full Screen

1import numpy as np2import csv3def get_model(model_name, power, test_window_size, power_window_size):4 """5 get score of model6 Args:7 model_name: str, we use model_name to find the folder8 power: ndarray, power of each fold to fuse9 test_window_size: list, the window_size we selected to fuse10 power_window_size: ndarray, power of each window_size to fuse11 Returns:12 score: score of model13 """14 out = np.zeros((634, 30), dtype='float32')15 power = power / power.sum()16 power_window_size = power_window_size / power_window_size.sum()17 for i in range(0, 5):18 for j in range(0, len(test_window_size)):19 path = "./output/%s_fold%s/score_%s.npy" % (model_name, i, test_window_size[j])20 print(path)21 data = np.load(path)22 out = out + data * power[i] * power_window_size[j]23 return out24def get_agcn():25 model_name = 'AGCN'26 power = np.array([1.5, 1, 1.5, 1, 2], dtype='float32')27 test_window_size = [300, 350, 500]28 power_window_size = np.array([1, 1, 1], dtype='float32')29 return get_model(model_name, power, test_window_size, power_window_size)30def get_ctrgcn():31 model_name = 'CTRGCN'32 power = np.array([1, 1, 2, 2, 3], dtype='float32')33 test_window_size = [300, 350, 450]34 power_window_size = np.array([1, 1, 1], dtype='float32')35 return get_model(model_name, power, test_window_size, power_window_size)36def get_ctrgcn2():37 model_name = 'CTRGCN2'38 power = np.array([1, 1, 2, 2, 3], dtype='float32')39 test_window_size = [350]40 power_window_size = np.array([1], dtype='float32')41 return get_model(model_name, power, test_window_size, power_window_size)42def get_stgcn():43 model_name = 'STGCN'44 power = np.array([1, 1, 2, 1, 2], dtype='float32')45 test_window_size = [350]46 power_window_size = np.array([1], dtype='float32')47 return get_model(model_name, power, test_window_size, power_window_size)48def get_effgcn():49 model_name = 'EFFGCN'50 power = np.array([1, 1, 2, 1, 3], dtype='float32')51 test_window_size = [500]52 power_window_size = np.array([1], dtype='float32')53 return get_model(model_name, power, test_window_size, power_window_size)54def get_all():55 out = np.zeros((634, 30), dtype='float32')56 data = []57 data.append(get_agcn())58 data.append(get_ctrgcn())59 data.append(get_ctrgcn2())60 data.append(get_stgcn())61 data.append(get_effgcn())62 power = np.array([2, 0.75, 1.5, 3.75, 2], dtype='float32')63 power = power / power.sum()64 for i in range(0, len(data)):65 out = out + data[i] * power[i]66 return out67def get_values_for_csv(data):68 values = []69 for i in range(0, data.shape[0]):70 j = np.argmax(data[i], axis=0)71 values.append((i, j))72 return values73def out_file(data, out_file):74 with open(75 out_file,76 'w',77 ) as fp:78 writer = csv.writer(fp)79 if out_file == "submission.csv":80 writer.writerow(['sample_index', 'predict_category'])81 writer.writerows(data)82if __name__ == "__main__":...

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