Best Python code snippet using toolium_python
functionality.py
Source:functionality.py  
...66            coded_length = len(item)67            if coded_length in self.codes.keys():68                continue69            elif coded_length in self.easy_codes.keys():70                self._update_dict(item, self.easy_codes.get(coded_length))71            # Create inversely mapped codes72            self.inv_codes = {v: k for k, v in self.codes.items()}73    def _update_dict(self, item, number):74        update_dict = {frozenset(item): number}75        self.codes.update(update_dict)76    def decode_hard_codes(self):77        """78        Uses encoded wireing to deduce the wireing not easily found by 79        decode_easy_codes().80        the numbers nine, six and zero have 6 active wires:81            if all active wires are also in the four it must be a nine82            if thats false, but all active wires are also in a one it 83            it must be a 084            If thats not the case it must be a six.85        the numbers three, five and two have 5 active wires:86            if it has all the wires also found in a seven it's a three87            if it has one less wire than a four it's a 588            and if it has two less wires than a four it's a 289        """90        for item in self.input_encoded + self.output_encoded:91            coded_length = len(item)92            if coded_length in self.codes.keys():93                continue94            this_number = frozenset(item)95            if coded_length == 6:96                if self.inv_codes.get(4) - this_number == set():97                    self._update_dict(item, 9)98                elif self.inv_codes.get(1) - this_number != set():99                    self._update_dict(item, 6)100                else:101                    self._update_dict(item, 0)102            elif coded_length == 5:103                if self.inv_codes.get(7) - this_number == set():104                    self._update_dict(item, 3)105                elif len(self.inv_codes.get(4) - this_number) == 1:106                    self._update_dict(item, 5)107                elif len(self.inv_codes.get(4) - this_number) == 2:108                    self._update_dict(item, 2)109            # Update inversely mapped codes110            self.inv_codes = {v: k for k, v in self.codes.items()}111    def decode_output(self):112        """113        Decode the message with decoded codes.114        Returns115        -------116        int117            A four digit integer where each wireing combination from 118            the output is one digit.119        """120        decoded = ""121        for item in self.output_encoded:122            decoded += str(self.codes.get(frozenset(item)))...layers.py
Source:layers.py  
...7def normalize(layer):8  return layer/127.5 - 1.9def denormalize(layer):10  return (layer + 1.)/2.11def _update_dict(layer_dict, scope, layer):12  name = "{}/{}".format(tf.get_variable_scope().name, scope)13  layer_dict[name] = layer14def image_from_paths(paths, shape, is_grayscale=True, seed=None):15  filename_queue = tf.train.string_input_producer(list(paths), shuffle=False, seed=seed)16  reader = tf.WholeFileReader()17  filename, data = reader.read(filename_queue)18  image = tf.image.decode_png(data, channels=3, dtype=tf.uint8)19  if is_grayscale:20    image = tf.image.rgb_to_grayscale(image)21  image.set_shape(shape)22  return filename, tf.to_float(image)23@add_arg_scope24def resnet_block(25    inputs, scope, num_outputs=64, kernel_size=[3, 3],26    stride=[1, 1], padding="SAME", layer_dict={}):27  with tf.variable_scope(scope):28    layer = conv2d(29        inputs, num_outputs, kernel_size, stride,30        padding=padding, activation_fn=tf.nn.relu, scope="conv1")31    layer = conv2d(32        layer, num_outputs, kernel_size, stride,33        padding=padding, activation_fn=None, scope="conv2")34    outputs = tf.nn.relu(tf.add(inputs, layer))35  _update_dict(layer_dict, scope, outputs)36  return outputs37@add_arg_scope38def repeat(inputs, repetitions, layer, layer_dict={}, **kargv):39  outputs = slim.repeat(inputs, repetitions, layer, **kargv)40  _update_dict(layer_dict, kargv['scope'], outputs)41  return outputs42@add_arg_scope43def conv2d(inputs, num_outputs, kernel_size, stride,44           layer_dict={}, activation_fn=None,45           #weights_initializer=tf.random_normal_initializer(0, 0.001),46           weights_initializer=tf.contrib.layers.xavier_initializer(),47           scope=None, name="", **kargv):48  outputs = slim.conv2d(49      inputs, num_outputs, kernel_size,50      stride, activation_fn=activation_fn, 51      weights_initializer=weights_initializer,52      biases_initializer=tf.zeros_initializer(dtype=tf.float32), scope=scope, **kargv)53  if name:54    scope = "{}/{}".format(name, scope)55  _update_dict(layer_dict, scope, outputs)56  return outputs57@add_arg_scope58def max_pool2d(inputs, kernel_size=[3, 3], stride=[1, 1],59               layer_dict={}, scope=None, name="", **kargv):60  outputs = slim.max_pool2d(inputs, kernel_size, stride, **kargv)61  if name:62    scope = "{}/{}".format(name, scope)63  _update_dict(layer_dict, scope, outputs)64  return outputs65@add_arg_scope66def tanh(inputs, layer_dict={}, name=None, **kargv):67  outputs = tf.nn.tanh(inputs, name=name, **kargv)68  _update_dict(layer_dict, name, outputs)...dir_dict.py
Source:dir_dict.py  
1from collections.abc import MutableMapping2from functools import wraps3from typing import Iterator4import os5def _update_dict(func):6    @wraps(func)7    def wrapper(self, *args, **kwargs):8        self._temp_dic = {}9        try:10            for file_name in os.listdir(self._path):11                with open(self._path + os.path.sep + file_name) as f:12                    self._temp_dict[file_name] = f.readline()13        except OSError:14            print("can't open " + str(self._path))15        return func(self, *args, **kwargs)16    return wrapper17class DirDict(MutableMapping):18    def __init__(self, path):19        self._path = path...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!!
