Best Python code snippet using avocado_python
gen_layer.py
Source: gen_layer.py
1from sklearn.utils import shuffle2from glob import glob3import os4import numpy as np5import makiflow6from makiflow.generators.pipeline.gen_base import PathGenerator7from makiflow.generators.segmentator.map_methods import SegmentIterator8from makiflow.generators.segmentator.map_methods import LoadDataMethod, ComputePositivesPostMethod, ResizePostMethod9from makiflow.generators.segmentator.map_methods import NormalizePostMethod, RGB2BGRPostMethod, SqueezeMaskPostMethod10from makiflow.generators.segmentator.gen_layers import InputGenLayer11import tensorflow as tf12from makiflow.generators.segmentator import (InputGenNumpyGetterLayer, data_reader_wrapper, data_resize_wrapper, 13 data_elastic_wrapper, AugmentationPostMethod)14class Generator(PathGenerator):15 def __init__(self, path_images, path_masks):16 self.images = glob(os.path.join(path_images, '*.bmp'))17 self.masks = glob(os.path.join(path_masks, '*.bmp'))18 for _ in range(50):19 self.images, self.masks = shuffle(self.images, self.masks)20 def next_element(self):21 index = 022 while True:23 index = np.random.randint(low=0, high=len(self.images))24 25 el = {26 SegmentIterator.IMAGE: self.images[index],27 SegmentIterator.MASK: self.masks[index]28 }29 30 yield el31def create_generator(path_images, path_masks):32 gen = Generator(path_images, path_masks).next_element()33 gen = data_reader_wrapper(gen, use_bgr2rgb=False)34 gen = data_resize_wrapper(gen, resize_to=(1024,1024))35 gen = data_elastic_wrapper(36 gen, alpha=500, std=5, num_maps=20, noise_invert_scale=15, seed=None,37 img_inter='linear', mask_inter='nearest', border_mode='reflect_101',38 keep_old_data=False, prob=0.939 )40 41 return gen42def get_gen_layer(data_gen_path, im_hw, batch_sz, prefetch_sz):43 path_images, path_masks = data_gen_path44 map_method = AugmentationPostMethod(45 use_rotation=True,46 angle_min=-60.0,47 angle_max=60.0,48 use_shift=False,49 dx_min=None,50 dx_max=None,51 dy_min=None,52 dy_max=None,53 use_zoom=False,54 zoom_min=0.9,55 zoom_max=1.156 )57 map_method = SqueezeMaskPostMethod()(map_method)58 #map_method = RGB2BGRPostMethod()(map_method)59 map_method = NormalizePostMethod(use_float64=True)(map_method)60 map_method = ComputePositivesPostMethod()(map_method)61 return InputGenNumpyGetterLayer(62 prefetch_size=prefetch_sz,63 batch_size=batch_sz,64 path_generator=create_generator(path_images, path_masks),65 name='Input',66 map_operation=map_method,67 num_parallel_calls=5,68 mask_shape=im_hw,69 image_shape=(im_hw[0], im_hw[1], 3)70 )71def main():72 makiflow.set_main_gpu(1)73 sess = tf.Session()74 75 import matplotlib.pyplot as plt76 #gen = create_generator(f'/raid/rustam/med_data/aspai_{1}/images', f'/raid/rustam/med_data/aspai_{1}/masks')77 #gen = Generator(f'/raid/rustam/med_data/aspai_{1}/images', f'/raid/rustam/med_data/aspai_{1}/masks')78 gen = get_generator(f'/raid/rustam/med_data/aspai_{1}/images', f'/raid/rustam/med_data/aspai_{1}/masks')79 t = gen.get_data_tensor()80 gen.get_iterator()81 plt.figure(figsize=(10, 10))82 plt.imshow(sess.run(t)[0].astype(np.uint8))83 plt.figure(figsize=(10, 10))...
get_init_map.py
Source: get_init_map.py
1# -*- coding: utf-8 -*-2"""3Created on Fri Jul 23 16:04:46 202145@author: zhoux6"""78legal_methods = {'naive', 'simulated_annealing'}910def get_init_map(DG, AG, map_method='naive'):11 '''12 Return13 map_list: represents a mapping in which indices and values stand for 14 logical and physical qubits.15 '''16 if not map_method in legal_methods:17 raise(Exception("Unsupported method {} for initial mapping".format(map_method)))18 if map_method == 'naive':19 return list(range(len(AG)))20 if map_method == 'simulated_annealing':21 from .sa_mapping import InitialMapSimulatedAnnealingWeighted22 return InitialMapSimulatedAnnealingWeighted(DG, AG)
...
Check out the latest blogs from LambdaTest on this topic:
Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.
In addition to the four values, the Agile Manifesto contains twelve principles that are used as guides for all methodologies included under the Agile movement, such as XP, Scrum, and Kanban.
JavaScript is one of the most widely used programming languages. This popularity invites a lot of JavaScript development and testing frameworks to ease the process of working with it. As a result, numerous JavaScript testing frameworks can be used to perform unit testing.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
The rapid shift in the use of technology has impacted testing and quality assurance significantly, especially around the cloud adoption of agile development methodologies. With this, the increasing importance of quality and automation testing has risen enough to deliver quality work.
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!!