How to use initialize_plugins method in avocado

Best Python code snippet using avocado_python

methods.py

Source:methods.py Github

copy

Full Screen

...77 self._model = create_instance(model)78 self._model.fc = nn.Linear(2048, 7, bias=False)79 self._optimizer = create_instance(optimizer, params=self._model.parameters())80 self._criterion = create_instance(criterion) 81 self._plugins = self.initialize_plugins()82 83 @property84 def model(self):85 return self._model86 87 @property88 def optimizer(self):89 return self._optimizer90 91 @property92 def criterion(self):93 return self._criterion94 95 @property96 def plugins(self):97 return self._plugins98 99 def initialize_plugins(self):100 return ClassStrategyPlugin()101 102 103class EWC(object):104 def __init__(self, 105 model: edict,106 optimizer: edict,107 criterion: edict108 ):109 110 self._model = create_instance(model)111 self._model.fc = nn.Linear(2048, 7, bias=False)112 self._optimizer = create_instance(optimizer, params=self._model.parameters())113 self._criterion = create_instance(criterion) 114 self._plugins = self.initialize_plugins()115 116 @property117 def model(self):118 return self._model119 120 @property121 def optimizer(self):122 return self._optimizer123 124 @property125 def criterion(self):126 return self._criterion127 128 @property129 def plugins(self):130 return self._plugins131 132 def initialize_plugins(self):133 return EWCPlugin(ewc_lambda=0.4, decay_factor=0.1, mode="online")134class Replay(object):135 def __init__(self, 136 model: edict,137 optimizer: edict,138 criterion: edict,139 mem_size: int,140 storage_policy: dict,141 selection_strategy: dict=None,142 features_based: bool=False143 ):144 145 self._model = create_instance(model)146 self._model.fc = nn.Linear(2048, 7, bias=False)147 self._optimizer = create_instance(optimizer, params=self._model.parameters())148 self._criterion = create_instance(criterion) 149 self._mem_size = mem_size150 151 # if features based exemplar strategy152 # feeding model and its layername for features extractor153 if features_based:154 self._selection_strategy = create_instance(selection_strategy, model=self._model) if not selection_strategy is None else None155 else: 156 self._selection_strategy = create_instance(selection_strategy) if not selection_strategy is None else None157 158 # create storage policy with selection strategy if pre-defined159 if self._selection_strategy:160 try:161 self._storage_policy = create_instance(storage_policy, selection_strategy=self._selection_strategy)162 self._storage_policy.ext_mem = dict()163 print(f"selection strategy: {self._selection_strategy}")164 except:165 self._storage_policy = create_instance(storage_policy)166 self._storage_policy.ext_mem = dict()167 print(f"Selection strategy: None")168 else:169 print(f"Selection strategy: None")170 self._storage_policy = create_instance(storage_policy)171 self._storage_policy.ext_mem = dict()172 173 self._plugins = self.initialize_plugins()174 175 @property176 def model(self):177 return self._model178 179 @property180 def optimizer(self):181 return self._optimizer182 183 @property184 def criterion(self):185 return self._criterion186 187 @property188 def plugins(self):189 return self._plugins190 191 def initialize_plugins(self):192 return ReplayPlugin(self._mem_size, self._storage_policy)193 194 195class SynapticIntelligence(object):196 def __init__(self, 197 model: edict,198 optimizer: edict,199 criterion: edict,200 si_lambda: float,201 excluded_parameters: str="fc"202 ):203 204 self._model = create_instance(model)205 self._model.fc = nn.Linear(2048, 7, bias=False)206 self._optimizer = create_instance(optimizer, params=self._model.parameters())207 self._criterion = create_instance(criterion) 208 self._si_lambda = si_lambda209 self._excluded_parameters = excluded_parameters210 self._plugins = self.initialize_plugins()211 212 @property213 def model(self):214 return self._model215 216 @property217 def optimizer(self):218 return self._optimizer219 220 @property221 def criterion(self):222 return self._criterion223 224 @property225 def plugins(self):226 return self._plugins227 228 def initialize_plugins(self):229 return SynapticIntelligencePlugin(si_lambda=self._si_lambda, 230 excluded_parameters=self._excluded_parameters)231 232class AGEM(object):233 def __init__(self, 234 model: edict,235 optimizer: edict,236 criterion: edict,237 **kwargs238 ):239 240 self._model = create_instance(model)241 self._model.fc = nn.Linear(2048, 7, bias=False)242 self._optimizer = create_instance(optimizer, params=self._model.parameters())243 self._criterion = create_instance(criterion) 244 self._kwargs = kwargs245 self._plugins = self.initialize_plugins()246 247 @property248 def model(self):249 return self._model250 251 @property252 def optimizer(self):253 return self._optimizer254 255 @property256 def criterion(self):257 return self._criterion258 259 @property260 def plugins(self):261 return self._plugins262 263 def initialize_plugins(self):264 return AGEMPlugin(**self._kwargs)265 266 267 268class LwF(object):269 def __init__(self, 270 model: edict,271 optimizer: edict,272 criterion: edict,273 ):274 275 self._model = create_instance(model)276 self._model.fc = nn.Linear(2048, 7, bias=False)277 self._optimizer = create_instance(optimizer, params=self._model.parameters())278 self._criterion = create_instance(criterion) 279 self._plugins = self.initialize_plugins()280 281 @property282 def model(self):283 return self._model284 285 @property286 def optimizer(self):287 return self._optimizer288 289 @property290 def criterion(self):291 return self._criterion292 293 @property294 def plugins(self):295 return self._plugins296 297 def initialize_plugins(self):298 return LwFPlugin()299 300 301 302class CoPE(object):303 def __init__(self, 304 model: edict,305 optimizer: edict,306 criterion: edict,307 **kwargs308 ):309 310 self._model = create_instance(model)311 self._model.fc = nn.Linear(2048, 7, bias=False)312 self._optimizer = create_instance(optimizer, params=self._model.parameters())313 self._criterion = create_instance(criterion) 314 self._kwargs = kwargs315 self._plugins = self.initialize_plugins()316 317 @property318 def model(self):319 return self._model320 321 @property322 def optimizer(self):323 return self._optimizer324 325 @property326 def criterion(self):327 return self._criterion328 329 @property330 def plugins(self):331 return self._plugins332 333 def initialize_plugins(self):334 return CoPEPlugin(**self._kwargs)335 336 337class CWRStar(object):338 def __init__(self, 339 model: edict,340 optimizer: edict,341 criterion: edict,342 **kwargs343 ):344 345 self._model = create_instance(model)346 self._model.fc = nn.Linear(2048, 7, bias=False)347 self._optimizer = create_instance(optimizer, params=self._model.parameters())348 self._criterion = create_instance(criterion) 349 self._kwargs = kwargs350 self._plugins = self.initialize_plugins()351 352 @property353 def model(self):354 return self._model355 356 @property357 def optimizer(self):358 return self._optimizer359 360 @property361 def criterion(self):362 return self._criterion363 364 @property365 def plugins(self):366 return self._plugins367 368 def initialize_plugins(self):...

Full Screen

Full Screen

detect_secrets.py

Source:detect_secrets.py Github

copy

Full Screen

...65 66 lineNum += 167 68 return json.dumps(secrets)69def initialize_plugins(hex_limit, base64_limit,exclude_lines_regex=None):70 plugins = []71 for pluginClass in import_plugins(()).values():72 plugins.append(pluginClass(base64_limit=base64_limit,hex_limit=hex_limit, exclude_lines_regex=exclude_lines_regex))73 return tuple(plugins)74 75def lambda_handler(event, context):76 # TODO implement77 78 try:79 data = event["data"]80 except KeyError as e:81 errorMsg = "Error(s): Attribute " + str(e) + " is missing in input data"82 return {83 'result': errorMsg84 }85 86 #initialise plugins87 try:88 exclude_lines_regex = None89 90 if("exclude_lines_regex" in event):91 exclude_lines_regex=event["exclude_lines_regex"]92 93 94 if("base64_limit" in event and "hex_limit" in event):95 plugins = initialize_plugins(hex_limit=event["hex_limit"],base64_limit=event["base64_limit"],exclude_lines_regex=exclude_lines_regex)96 elif("base64_limit" in event):97 plugins = initialize_plugins(base64_limit=event["base64_limit"],hex_limit=hex_limit,exclude_lines_regex=exclude_lines_regex)98 elif("hex_limit" in event):99 plugins = initialize_plugins(hex_limit=event["hex_limit"],base64_limit=base64_limit,exclude_lines_regex=exclude_lines_regex)100 else:101 plugins = initialize_plugins(base64_limit=base64_limit,hex_limit=hex_limit, exclude_lines_regex=exclude_lines_regex)102 103 except ValueError as e:104 return {105 'result': "Error(s): invalid hex_limt/base64_limit" 106 }107 except TypeError as e:108 return {109 'result': "Error(s): " + str(e)110 }111 112 if("mode" in event):113 if(event['mode'] == 'debug'):114 result = scan_secrets(data,plugins)115 return {116 'result' : result117 }118 result = scan_secrets_counts(data,plugins)119 120 return {121 'result': result122 123 }124# if __name__ == "__main__":125# event = {126# "data": "AWSsecret = AKIA1212121212121212\nsecret = AYje346w846mgvitmon2amz02awa8bjg3g",127# "hex_limit": 1,128# "base64_limit": 1,129# "exclude_lines_regex" : "AKIA"130# }131# x = lambda_handler(event,"")132# print(x)133# # print(x)134# # plugins = initialize_plugins(1,1, "12")135# # x = 'AWSsecret = AKIA1212121212121212\nsecret = AYje346w846mgvitmon2amz02awa8bjg3g'136# # result = scan_screts(x, plugins)137# # print(result)...

Full Screen

Full Screen

__init__.py

Source:__init__.py Github

copy

Full Screen

...11 app = initialize_flask_app()12 app.config.from_object(config)13 with app.app_context():14 # Initialize Plugins15 initialize_plugins(app)16 # Register blueprints17 register_blueprints(app)18 register_restful_api(app)19 configure_database(app)...

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