Best Python code snippet using localstack_python
models.py
Source: models.py
1import tensorflow as tf2slim = tf.contrib.slim3from tensorflow.contrib.slim.nets import inception4import inception_resnet_v25import inception_v46import densenet7import numpy as np8class densenet_model:9 def __init__(self, model_path, model='denset169', new_scope=None):10 self.image_size = 29911 self.num_labels = 100012 self.num_channels = 313 self.new_scope = new_scope14 15 assert model in ['densenet169']16 if model == 'densenet169':17 self.arg_scope = densenet.densenet_arg_scope18 self.inception_model = densenet.densenet16919 self.scope='densenet169'20 x_input = tf.placeholder(tf.float32, shape=(None,self.image_size,self.image_size,self.num_channels))21 if self.new_scope is None:22 self.new_scope = self.scope 23 self.model_path = model_path24 self.mean = np.array([123.68, 116.78, 103.94]).reshape(1,1,1,3)25 self.scale_factor = 0.01726 self.first = True27 def initialize(self, sess):28 self.saver.restore(sess, self.model_path)29 def predict(self, img):30 # from inception preprocess to densenet preprocess:31 img = ((img+1) *127.5 - self.mean) * self.scale_factor32 reuse = not self.first33 with slim.arg_scope(self.arg_scope()):34 _, end_points = self.inception_model(35 img, num_classes=self.num_labels, is_training=False, reuse=reuse, scope=self.new_scope)36 if self.first:37 if self.scope != self.new_scope:38 var_dict = {var.op.name.replace(self.new_scope, self.scope, 1): var 39 for var in slim.get_model_variables(scope=self.new_scope)}40 else:41 var_dict = slim.get_model_variables(scope=self.scope)42 self.saver = tf.train.Saver(var_dict)43 self.first = False44 return end_points['Logits']45class inception_model:46 def __init__(self, model_path, model='inception_v3', new_scope=None):47 self.image_size = 29948 self.num_labels = 100149 self.num_channels = 350 self.new_scope = new_scope51 52 assert model in ['inception_v3', 'inception_v4', 'inception_resnet_v2', 'densenet']53 if model == 'inception_v3':54 self.arg_scope = inception.inception_v3_arg_scope55 self.inception_model = inception.inception_v356 self.scope='InceptionV3'57 elif model == 'inception_v4':58 self.arg_scope = inception_v4.inception_v4_arg_scope59 self.inception_model = inception_v4.inception_v460 self.scope='InceptionV4'61 elif model == 'inception_resnet_v2':62 self.arg_scope = inception_resnet_v2.inception_resnet_v2_arg_scope63 self.inception_model = inception_resnet_v2.inception_resnet_v264 self.scope='InceptionResnetV2'65 elif model == 'densenet':66 self.arg_scope = densenet.densenet_arg_scope67 self.inception_model = densenet.densenet16968 self.scope='densenet169'69 x_input = tf.placeholder(tf.float32, shape=(None,self.image_size,self.image_size,self.num_channels))70 if self.new_scope is None:71 self.new_scope = self.scope 72 self.first = True73 self.model_path = model_path74 def initialize(self, sess):75 self.saver.restore(sess, self.model_path)76 def predict(self, img):77 reuse = not self.first78 with slim.arg_scope(self.arg_scope()):79 _, end_points = self.inception_model(80 img, num_classes=self.num_labels, is_training=False, reuse=reuse, scope=self.new_scope)81 if self.first:82 if self.scope != self.new_scope:83 var_dict = {var.op.name.replace(self.new_scope, self.scope, 1): var 84 for var in slim.get_model_variables(scope=self.new_scope)}85 else:86 var_dict = slim.get_model_variables(scope=self.scope)87 self.saver = tf.train.Saver(var_dict)88 self.first = False...
scope.py
Source: scope.py
1from typing import List, Any, Dict, Optional, Union, Set2from crytic_compile.utils.naming import Filename3from slither.core.declarations import Contract, Import, Pragma4from slither.core.declarations.custom_error_top_level import CustomErrorTopLevel5from slither.core.declarations.enum_top_level import EnumTopLevel6from slither.core.declarations.function_top_level import FunctionTopLevel7from slither.core.declarations.structure_top_level import StructureTopLevel8from slither.slithir.variables import Constant9def _dict_contain(d1: Dict, d2: Dict) -> bool:10 """11 Return true if d1 is included in d212 """13 d2_keys = d2.keys()14 return all(item in d2_keys for item in d1.keys())15# pylint: disable=too-many-instance-attributes16class FileScope:17 def __init__(self, filename: Filename):18 self.filename = filename19 self.accessible_scopes: List[FileScope] = []20 self.contracts: Dict[str, Contract] = {}21 # Custom error are a list instead of a dict22 # Because we parse the function signature later on23 # So we simplify the logic and have the scope fields all populated24 self.custom_errors: Set[CustomErrorTopLevel] = set()25 self.enums: Dict[str, EnumTopLevel] = {}26 # Functions is a list instead of a dict27 # Because we parse the function signature later on28 # So we simplify the logic and have the scope fields all populated29 self.functions: Set[FunctionTopLevel] = set()30 self.imports: Set[Import] = set()31 self.pragmas: Set[Pragma] = set()32 self.structures: Dict[str, StructureTopLevel] = {}33 def add_accesible_scopes(self) -> bool:34 """35 Add information from accessible scopes. Return true if new information was obtained36 :return:37 :rtype:38 """39 learn_something = False40 for new_scope in self.accessible_scopes:41 if not _dict_contain(new_scope.contracts, self.contracts):42 self.contracts.update(new_scope.contracts)43 learn_something = True44 if not new_scope.custom_errors.issubset(self.custom_errors):45 self.custom_errors |= new_scope.custom_errors46 learn_something = True47 if not _dict_contain(new_scope.enums, self.enums):48 self.enums.update(new_scope.enums)49 learn_something = True50 if not new_scope.functions.issubset(self.functions):51 self.functions |= new_scope.functions52 learn_something = True53 if not new_scope.imports.issubset(self.imports):54 self.imports |= new_scope.imports55 learn_something = True56 if not new_scope.pragmas.issubset(self.pragmas):57 self.pragmas |= new_scope.pragmas58 learn_something = True59 if not _dict_contain(new_scope.structures, self.structures):60 self.structures.update(new_scope.structures)61 learn_something = True62 return learn_something63 def get_contract_from_name(self, name: Union[str, Constant]) -> Optional[Contract]:64 if isinstance(name, Constant):65 return self.contracts.get(name.name, None)66 return self.contracts.get(name, None)67 # region Built in definitions68 ###################################################################################69 ###################################################################################70 def __eq__(self, other: Any) -> bool:71 if isinstance(other, str):72 return other == self.filename73 return NotImplemented74 def __neq__(self, other: Any) -> bool:75 if isinstance(other, str):76 return other != self.filename77 return NotImplemented78 def __str__(self) -> str:79 return str(self.filename.relative)80 def __hash__(self) -> int:81 return hash(self.filename.relative)...
Check out the latest blogs from LambdaTest on this topic:
The fact is not alien to us anymore that cross browser testing is imperative to enhance your application’s user experience. Enhanced knowledge of popular and highly acclaimed testing frameworks goes a long way in developing a new app. It holds more significance if you are a full-stack developer or expert programmer.
QA testers have a unique role and responsibility to serve the customer. Serving the customer in software testing means protecting customers from application defects, failures, and perceived failures from missing or misunderstood requirements. Testing for known requirements based on documentation or discussion is the core of the testing profession. One unique way QA testers can both differentiate themselves and be innovative occurs when senseshaping is used to improve the application user experience.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!