How to use fill_with method in Selene

Best Python code snippet using selene_python

Displayer.py

Source:Displayer.py Github

copy

Full Screen

...42 {'edit_lot': "not yet implemented"}43 44 def clear_display(self):45 for key, display in self.displays:46 display.fill_with(None)474849class Display:50 """Display handles presenting information on the screen's user interface.51 Most of its methods display some part of an Item object."""52 def __init__(self, user_interface):53 self.ui = user_interface54 self.classify_interfaces()55 56 def classify_interfaces(self):57 ####################################################58 self.basic_display = \59 {'item_number': Label(self.ui.is_item_numberL,60 none_msg = "Item not found."),61 'name' : Label(self.ui.is_item_nameL),62 'fridge' : Label(self.ui.is_fridgeL),63 'note' : PlainText(self.ui.is_item_notePT)}64 ####################################################65 self.allergens_display = Label(self.ui.is_allergensL,66 none_msg = "None")67 ####################################################68 self.pesticides_display = Label(self.ui.is_pesticideL,69 none_msg = "No Spec")70 ####################################################71 self.hm_display = \72 {'arsenic': Label(self.ui.is_as_maxL,73 none_msg = "N/A"),74 'cadmium': Label(self.ui.is_cd_maxL,75 none_msg = "N/A"),76 'lead': Label(self.ui.is_pb_maxL,77 none_msg = "N/A"),78 'mercury': Label(self.ui.is_hg_maxL,79 none_msg = "N/A"),80 'arsenic_units': Label(self.ui.is_as_unitL),81 'cadmium_units': Label(self.ui.is_cd_unitL),82 'lead_units': Label(self.ui.is_pb_unitL),83 'mercury_units': Label(self.ui.is_hg_unitL),}84 ####################################################85 self.organo_display = \86 {'color': Label(self.ui.is_colorL,87 none_msg = "N/A"),88 'odor': Label(self.ui.is_odorL,89 none_msg = "N/A"),90 'appearance': Label(self.ui.is_appearanceL,91 none_msg = "N/A")} 92 ####################################################93 self.density_display = \94 {'flow': Label(self.ui.is_flow_densityL,95 none_msg = "N/A"),96 'tap': Label(self.ui.is_tap_densityL,97 none_msg = "N/A")}98 #################################################### 99 self.avgwt_display = Label(self.ui.is_avgwtL,100 none_msg = "N/A")101 ####################################################102 self.moisture_display = Label(self.ui.is_moistureL,103 none_msg = "N/A")104 ####################################################105 self.microbes_display = \106 {'tpc': Label(self.ui.is_tpcL,107 none_msg = "N/A"),108 'ym': Label(self.ui.is_ymL,109 none_msg = "N/A")}110 ####################################################111 self.pathogens_display = \112 {'ecoli': Label(self.ui.is_ecoliL,113 none_msg = "Not Tested."),114 'salmonella': Label(self.ui.is_salmonellaL,115 none_msg = "Not Tested."),116 'staph': Label(self.ui.is_staphL,117 none_msg = "Not Tested.")}118 ####################################################119 self.assay_display = \120 {'assays': List(self.ui.is_assayList),121 'spec': Label(self.ui.is_assay_specL),122 'method': Label(self.ui.is_assay_methodL),123 'dry_basis': Label(self.ui.is_dbL)}124 ####################################################125 self.chem_display = \126 {'chems': List(self.ui.is_chemList),127 'method': Label(self.ui.is_chem_methodL),128 'presence': Label(self.ui.is_chem_presenceL)}129 ####################################################130 self.plant_display = \131 {'plants': List(self.ui.is_plantList),132 'part': Label(self.ui.is_plant_partL),133 'solvent': Label(self.ui.is_plant_solventL),134 'method': Label(self.ui.is_plant_methodL)}135 ####################################################136 self.lot_display = List(self.ui.il_lotList)137 ####################################################138 self.lot_basics_display = \139 {'lot_number': Label(self.ui.il_lot_numberL),140 'vendor': Label(self.ui.il_vendorL),141 'vendor_lot': Label(self.ui.il_vendor_lotL),142 'lot_note': PlainText(self.ui.il_lot_notePT),143 'delay_note': PlainText(self.ui.il_lot_delayPT),144 'expected': Label(self.ui.il_expected_dateL,145 none_msg = 'Unknown'),146 'actual': Label(self.ui.il_final_dateL,147 none_msg = 'Not yet released')}148 ####################################################149 self.lot_receiving_display = \150 {'amount': Label(self.ui.il_amount_recL),151 'date': Label(self.ui.il_date_recL,152 none_msg = 'Unknown'),153 'po': Label(self.ui.il_rec_poL,154 none_msg = 'Unknown')}155 ####################################################156 self.lot_location_display = \157 {'facility': Label(self.ui.il_facilityL),158 'warehouse': Label(self.ui.il_wh_codeL)}159 ####################################################160 self.lot_assay_display = \161 {'assays': List(self.ui.il_assay_resultList),162 'spec': Label(self.ui.il_assay_specL),163 'result': Label(self.ui.il_assay_resultL,164 none_msg = "No result yet")}165 ####################################################166 self.lot_chem_id_display = \167 {'chem_ids': List(self.ui.il_chem_id_resultList),168 'spec': Label(self.ui.il_chem_id_specL),169 'result': Label(self.ui.il_chem_id_resultL,170 none_msg = 'No result yet.')}171 ####################################################172 self.lot_plant_display = \173 {'plants': Table(self.ui.il_plant_id_resultTable),174 'spec' : Label(self.ui.il_plant_id_specL),175 'result': Label(self.ui.il_plant_id_resultL,176 none_msg = 'No result yet.')}177 ####################################################178 self.lot_micro_display = \179 {'micro': Table(self.ui.il_microTable)}180 ####################################################181 self.lot_hm_display = \182 {'hm': Table(self.ui.il_hmTable)}183 ####################################################184 self.lot_pest_display = \185 {'table': Table(self.ui.il_pesticideTable)}186 ####################################################187 188 def show_item(self, item):189 self.run_item_displays(item)190 self.disable_item_entry()191 self.enable_assay_entry(item.assays)192 self.enable_chem_entry(item.chem_ids)193 self.enable_plant_entry(item.plant_ids)194 self.enable_other_button_entry(item)195 196 def show_lot(self, lot):197 self.run_lot_displays(lot)198 199 def run_item_displays(self, item):200 self.display_basic(item)201 self.display_chem_ids(item.chem_ids)202 self.display_plant_ids(item.plant_ids)203 self.display_assays(item.assays) 204 self.display_allergens(item.allergens)205 self.display_organoleptics(item.organoleptics)206 self.display_moisture(item.moisture)207 self.display_density(item.density)208 self.display_avgwt(item.avgwt)209 self.display_microbes(item.microbes)210 self.display_pathogens(item.pathogens)211 self.display_heavy_metals(item.hm)212 self.display_pesticides(item.pesticides)213 self.display_lots(item.lots)214 215 def run_lot_displays(self, lot):216 self.display_lot_basic(lot)217 self.display_lot_receiving(lot.receiving)218 self.display_lot_location(lot.location)219 self.display_lot_assays(lot.assay_results)220 self.display_lot_chems(lot.chem_id_results)221 self.display_lot_plants(lot.plant_id_results)222 self.display_lot_micros(lot.microbes_result, lot.pathogens_result)223 self.display_lot_hm(lot.hm_result)224 self.display_lot_pesticides(lot.pesticides_result)225 226 def disable_item_entry(self):227 pass228 """229 self.ui.is_edit_hmB.setEnabled(False)230 self.ui.is_edit_microbeB.setEnabled(False)231 self.ui.is_edit_organolepticB.setEnabled(False)232 self.ui.is_edit_physicalB.setEnabled(False)233 self.ui.is_edit_pesticideB.setEnabled(False)234 self.ui.is_edit_basicB.setEnabled(False)235 #new236 self.ui.is_new_chem_idB.setEnabled(False)237 self.ui.is_new_plant_idB.setEnabled(False)238 self.ui.is_new_assayB.setEnabled(False)239 #edit240 self.ui.is_edit_chem_idB.setEnabled(False)241 self.ui.is_edit_plant_idB.setEnabled(False)242 self.ui.is_edit_assayB.setEnabled(False)243 #remove244 self.ui.is_remove_chem_idB.setEnabled(False)245 self.ui.is_remove_plant_idB.setEnabled(False)246 self.ui.is_remove_assayB.setEnabled(False)247 """248 249 #TODO for these functions, place a search_found variable in Interactive_RawItem250 #enable or disable these according to if it was found in the SearchButton251 #sequester the table functions in that class252 def enable_assay_entry(self, assays):253 pass254 """255 if assays.data is not None:256 self.ui.is_new_assayB.setEnabled(True)257 selected_assay = self.ui.is_assayTable.currentRow()258 if selected_assay != -1: 259 self.ui.is_edit_assayB.setEnabled(True)260 self.ui.is_remove_assayB.setEnabled(True)261 """262 263 def enable_chem_entry(self, chem_ids):264 pass265 """266 if chem_ids.data is not None:267 self.ui.is_new_chem_idB.setEnabled(True)268 selected_chem = self.ui.is_chem_idTable.currentRow()269 if selected_chem != -1:270 self.ui.is_edit_chem_idB.setEnabled(True)271 self.ui.is_remove_chem_idB.setEnabled(True)272 """273 274 def enable_plant_entry(self, plant_ids):275 pass276 """277 if plant_ids.data is not None:278 self.ui.is_new_plant_idB.setEnabled(True)279 selected_plant = self.ui.is_plant_idTable.currentRow()280 if selected_plant != -1:281 self.ui.is_edit_plant_idB.setEnabled(True)282 self.ui.is_remove_plant_idB.setEnabled(True)283 """284 285 def enable_other_button_entry(self, item):286 pass287 """288 if item.data is not None:289 self.ui.is_edit_hmB.setEnabled(True)290 self.ui.is_edit_microbeB.setEnabled(True)291 self.ui.is_edit_organolepticB.setEnabled(True)292 self.ui.is_edit_physicalB.setEnabled(True)293 self.ui.is_edit_pesticideB.setEnabled(True)294 self.ui.is_edit_basicB.setEnabled(True)295 """ 296297 def blank_all(self, interface_dict):298 for key, item in interface_dict.items():299 item.fill_with(None)300 301 #def display_basic(self, basic_data, basic_displays *args):302 # if basic_data is not None:303 # for display in basic_displays:304 # filler = getattr(basic_data, arg)305 # display.fill_with(filler)306 307 def display_basic(self, basic):308 if basic is not None and basic.data is not None:309 self.basic_display['item_number'].fill_with(basic.data.id)310 self.basic_display['name']. fill_with(basic.data.name)311 self.basic_display['fridge']. fill_with(basic.fridge_string())312 self.basic_display['note']. fill_with(basic.data.note) 313 else:314 self.blank_all(self.basic_display)315 316 def display_allergens(self, allergens):317 if allergens.data is not None:318 self.allergens_display.fill_with(allergens.allergen_string())319 else:320 self.allergens_display.fill_with(None) 321 322 def display_pesticides(self, pesticides):323 if pesticides.data is not None:324 self.pesticides_display.fill_with(pesticides.data.standard)325 else:326 self.pesticides_display.fill_with(None)327328 def display_heavy_metals(self, heavy_metals):329 if heavy_metals.data is not None:330 self.hm_display['arsenic'].fill_with(heavy_metals.data.arsenic_max)331 self.hm_display['cadmium'].fill_with(heavy_metals.data.cadmium_max)332 self.hm_display['lead'].fill_with(heavy_metals.data.lead_max)333 self.hm_display['mercury'].fill_with(heavy_metals.data.mercury_max)334 self.hm_display['arsenic_units'].fill_with(heavy_metals.data.units)335 self.hm_display['cadmium_units'].fill_with(heavy_metals.data.units)336 self.hm_display['lead_units'].fill_with(heavy_metals.data.units)337 self.hm_display['mercury_units'].fill_with(heavy_metals.data.units)338 else:339 self.blank_all(self.hm_display)340 341 def display_organoleptics(self, organoleptics):342 if organoleptics.data is not None:343 self.organo_display['color'].\344 fill_with(organoleptics.data.color)345 self.organo_display['odor'].\346 fill_with(organoleptics.data.odor)347 self.organo_display['appearance'].\348 fill_with(organoleptics.data.appearance)349 else:350 self.blank_all(self.organo_display) 351352 def display_density(self, density):353 if density.data is not None:354 self.density_display['flow'].fill_with(density.flow_range())355 self.density_display['tap'].fill_with(density.tap_range())356 else:357 self.blank_all(self.density_display)358 359 def display_moisture(self, moisture):360 if moisture.data is not None:361 self.moisture_display.fill_with(moisture.moisture_range())362 else:363 self.moisture_display.fill_with(None)364 365 def display_avgwt(self, avgwt):366 if avgwt is not None:367 self.avgwt_display.fill_with(avgwt.avgwt_range())368 else:369 self.avgwt_display.fill_with(None)370371 def display_microbes(self, microbes):372 if microbes.data is not None:373 self.microbes_display['tpc'].fill_with(microbes.tpc_range())374 self.microbes_display['ym'].fill_with(microbes.ym_range())375 else:376 self.blank_all(self.microbes_display)377 378 def display_pathogens(self, pathogens):379 if pathogens.data is not None:380 self.pathogens_display['ecoli'].\381 fill_with(pathogens.ecoli_status_string())382 self.pathogens_display['salmonella'].\383 fill_with(pathogens.salmonella_status_string())384 self.pathogens_display['staph'].\385 fill_with(pathogens.staph_status_string())386 else:387 self.blank_all(self.pathogens_display)388389 def display_assays(self, assays):390 if assays.data is not None:391 self.assay_display['assays'].clear()392 for key, assay in assays.specific.items():393 self.assay_display['assays'].fill_with(key)394 else:395 self.blank_all(self.assay_display)396397 def assay_selected(self, assays):398 key = self.assay_display['assays'].current_item()399 if key is not None:400 self.assay_display['spec'].fill_with(assays.specific[key].assay_range())401 self.assay_display['method'].fill_with(assays.specific[key].data.method)402 self.assay_display['dry_basis'].fill_with(assays.specific[key].dry_basis_string())403404 def display_chem_ids(self, chem_ids):405 if chem_ids.data is not None:406 self.chem_display['chems'].clear()407 for key, chem in chem_ids.specific.items():408 self.chem_display['chems'].fill_with(key)409 else:410 self.blank_all(self.chem_display)411412 def chem_selected(self, chem_ids):413 key = self.chem_display['chems'].current_item()414 if key is not None:415 self.chem_display['method'].fill_with(chem_ids.specific[key].data.method)416 self.chem_display['presence'].fill_with(chem_ids.specific[key].presence_string())417418 def display_plant_ids(self, plant_ids):419 if plant_ids.data is not None:420 self.plant_display['plants'].clear()421 for key, plant in plant_ids.specific.items():422 self.plant_display['plants'].fill_with(key)423 else:424 self.blank_all(self.plant_display)425426 def plant_selected(self, plant_ids):427 key = self.plant_display['plants'].current_item()428 if key is not None:429 self.plant_display['part'].fill_with(plant_ids.specific[key].data.part)430 self.plant_display['solvent'].fill_with(plant_ids.specific[key].data.solvent)431 self.plant_display['method'].fill_with(plant_ids.specific[key].data.method)432 433 def display_lots(self, lots):434 if lots is not None and lots.data is not None:435 self.lot_display.clear()436 for key, lot in lots.specific.items():437 self.lot_display.fill_with(key)438439 440 #display these only when a lot is selected441 def display_lot_basic(self, basics):442 if basics.data is not None:443 self.lot_basics_display['lot_number'].\444 fill_with(basics.data.lot_number)445 self.lot_basics_display['vendor'].\446 fill_with(basics.data.vendor)447 self.lot_basics_display['vendor_lot'].\448 fill_with(basics.data.vendor_lot)449 self.lot_basics_display['lot_note'].\450 fill_with(basics.data.lot_note)451 self.lot_basics_display['delay_note'].\452 fill_with(basics.data.delay_note)453 self.lot_basics_display['expected'].\454 fill_with(basics.data.expected_release_date)455 self.lot_basics_display['actual'].\456 fill_with(basics.data.actual_release_date)457 else:458 self.blank_all(self.lot_basics_display)459 460 def display_lot_receiving(self, receiving):461 if receiving.data is not None:462 self.lot_receiving_display['amount'].\463 fill_with(receiving.amount_string())464 self.lot_receiving_display['date'].\465 fill_with(receiving.date_string())466 self.lot_receiving_display['po'].\467 fill_with(receiving.data.po)468 else:469 self.blank_all(self.lot_receiving_display)470 471 def display_lot_location(self, location):472 if location.data is not None:473 self.lot_location_display['facility'].\474 fill_with(location.data.facility)475 self.lot_location_display['warehouse'].\476 fill_with(location.data.wh_code)477 else:478 self.blank_all(self.lot_location_display)479480 def display_lot_plants(self, plant_ids):481 self.lot_plant_display['plants'].clear()482 if plant_ids.specific:483 for result_id, result in plant_ids.specific.items():484 if result.data is not None and result.data.spec is not None:485 self.lot_plant_display['plants'].\486 fill_with(result.genus_string(), result.species_string())487 self.lot_plant_display['spec'].fill_with('Select plant ID')488 self.lot_plant_display['result'].fill_with('Select plant ID')489 490 def lot_plant_id_selected(self, plant_ids, plant_name):491 for result_id, plant_result in plant_ids.specific.items():492 if plant_result.data is not None \493 and plant_result.data.spec is not None \494 and plant_result.data.spec.genus_species == plant_name:495 self.lot_plant_display['spec'].\496 fill_with("Positive")497 self.lot_plant_display['result'].\498 fill_with(plant_result.data.result)499 break500 else:501 print("Warning: No spec for %s plant ID found." % plant_name)502503 def display_lot_assays(self, assays):504 self.lot_assay_display['assays'].clear()505 if assays.specific:506 print("had an assay")507 for result_id, result in assays.specific.items():508 if result.data is not None and result.data.spec is not None:509 self.lot_assay_display['assays'].\510 fill_with(result.data.spec.name)511 else:512 print("did no have an assay")513 self.lot_assay_display['spec'].fill_with("Select assay")514 self.lot_assay_display['result'].fill_with("Select assay")515 516 517 def lot_assay_selected(self, assays, assay_name):518 for result_id, assay_result in assays.specific.items():519 if assay_result.data is not None \520 and assay_result.data.spec is not None \521 and assay_result.data.spec.name == assay_name:522 self.lot_assay_display['spec'].\523 fill_with(assay_result.assay_range())524 self.lot_assay_display['result'].\525 fill_with(assay_result.data.result)526 break527 else:528 print("Warning: No spec for %s assay found." % assay_name)529530 def display_lot_chems(self, chem_ids):531 self.lot_chem_id_display['chem_ids'].clear()532 if chem_ids.specific:533 for result_id, result in chem_ids.specific.items():534 if result.data.spec is not None:535 self.lot_chem_id_display['chem_ids'].\536 fill_with(result.data.spec.name)537 self.lot_chem_id_display['spec'].\538 fill_with("Select chem ID")539 self.lot_chem_id_display['result'].\540 fill_with("Select chem ID")541 542 def lot_chem_id_selected(self, chem_ids, chem_name):543 for result_id, chem_result in chem_ids.specific.items():544 if chem_result.data is not None \545 and chem_result.data.spec is not None \546 and chem_result.data.spec.name == chem_name:547 self.lot_chem_id_display['spec'].\548 fill_with(chem_result.presence_string())549 self.lot_chem_id_display['result'].\550 fill_with(chem_result.data.result)551 break552 else:553 print("Warning: No spec for %s ID found." % chem_name) 554555 def display_lot_micros(self, microbes_result, pathogens_result):556 self.lot_micro_display['micro'].table.clearContents()557 self.lot_micro_display['micro'].\558 fill_vertical(microbes_result.tpc_result_string(),559 microbes_result.ym_result_string())560 self.lot_micro_display['micro'].\561 fill_vertical(pathogens_result.ecoli_result_string(),562 pathogens_result.salmonella_result_string(),563 pathogens_result.staph_result_string(),564 start_row = 2) ...

Full Screen

Full Screen

account_view.py

Source:account_view.py Github

copy

Full Screen

...10 def __init__(self):11 super().__init__()12 def __print_statements_header(self, title, account):13 # Configures info to be shown in header14 branch_info = self.fill_with('Branch:', 18)15 branch_info = '{0}{1:08d}'.format(branch_info, account.branch_id)16 account_info = self.fill_with('Account Number:', 18)17 account_info = '{0}{1:08d}'.format(account_info, account.number)18 client_info = self.fill_with('Client:', 18)19 client_info = '{0}{1:<}'.format(client_info, account.client.name)20 date_str = datetime.now().strftime('%Y/%m/%d')21 date_info = self.fill_with('Date:', 18)22 date_info = '{0}{1:<}'.format(date_info, date_str)23 # Prints the header24 self.print_header(title, branch_info, account_info,25 client_info, date_info)26 def __print_balance(self, account):27 pattern = self.get_line_pattern(BaseView.ALIGN_RIGHT)28 balance = account.get_balance()29 balance_str = 'TOTAL BALANCE: {0:.2f}'.format(balance)30 self.print_empty_header_line()31 print(pattern.format(balance_str))32 self.print_empty_header_line()33 self.print_border_line()34 self.wait_for_user()35 def create_account(self):36 try:37 data = {}38 self.print_header("CREATE NEW ACCOUNT")39 self.print_empty_lines(2)40 # TODO - Validate number and branch_id for integer input41 #number = input(self.fill_with('Account number (number):', 30))42 number_label = self.fill_with('Account number (number):', 30)43 account_number = random.randint(1, 999999)44 branch_id = input(self.fill_with('Branch id (number):', 30))45 data['branch_id'] = int(branch_id)46 data['number'] = account_number47 print('{0}{1:08d}'.format(number_label, account_number))48 data['name'] = input(self.fill_with('Client name:', 30))49 data['email'] = input(self.fill_with('Client email:', 30))50 data['login'] = input(self.fill_with('Client login:', 30))51 pwd = LoginView.input_password(self.fill_with('Password:', 30))52 data['password'] = pwd53 return data54 except Exception as e:55 self.show_message('ERROR', e.args[0], True)56 def show_client_accounts(self, accounts):57 self.print_header("CLIENT ACCOUNT LIST")58 self.print_empty_header_line()59 # Prints column headers60 pattern = '# {0:<6} | {1:<8} | {2:<7} | {3:<15} | {4:<15} | {5:<10} #'61 print(pattern.format('Branch', 'Account',62 'Cli. Id', 'Name', 'Email', 'Login'))63 # Prints line divider and column values64 self.print_line_divider()65 pattern = '# {0:06d} | {1:08d} | {2:07d} | {3:<15} | {4:<15} | {5:<10} #'66 for account in accounts:67 print(pattern.format(account.branch_id,68 account.number,69 account.client.id,70 account.client.name,71 account.client.email,72 account.client.login73 ))74 self.print_empty_header_line()75 self.print_border_line()76 self.wait_for_user()77 def create_transaction(self, tx_type):78 try:79 data = {}80 self.print_header(tx_type)81 # TODO Validate date and amout for type before conversion82 # and allow user to try again83 date_str = input(self.fill_with('Date (YYYY/MM/DD):', 20))84 data['date'] = datetime.strptime(date_str, '%Y/%m/%d')85 data['description'] = input(self.fill_with('Description:', 20))86 amout_str = input(self.fill_with('Amount:', 20))87 data['amount'] = float(amout_str)88 return data89 except Exception as e:90 self.show_message('Error', e.args[0], True)91 def show_statement(self, account):92 self.__print_statements_header('ACCOUNT STATEMENT', account)93 # Prints table header94 pattern = '# {0:<15} | {1:<30} | {2:^7} | {3:>15} #'95 print(pattern.format('Date', 'Description', 'Type', 'Amount'))96 # Prints table divider and column values97 pattern = '# {0:<15} | {1:<30} | {2:^7} | {3:>15} #'98 self.print_line_divider()99 for tx in account.get_transaction_history():100 print(pattern.format(tx.date.strftime('%Y/%m/%d'),...

Full Screen

Full Screen

segmentation_transforms.py

Source:segmentation_transforms.py Github

copy

Full Screen

1import numpy as np2from PIL import Image3import random4import torch5from torchvision import transforms as T6from torchvision.transforms import functional as F7def pad_if_smaller(img, size, fill=0):8 min_size = min(img.size)9 if min_size < size:10 ow, oh = img.size11 padh = size - oh if oh < size else 012 padw = size - ow if ow < size else 013 img = F.pad(img, (0, 0, padw, padh), fill=fill)14 return img15class Compose(object):16 def __init__(self, transforms):17 self.transforms = transforms18 def __call__(self, image, target):19 for t in self.transforms:20 image, target = t(image, target)21 return image, target22class RandomResize(object):23 def __init__(self, min_size, max_size=None):24 self.min_size = min_size25 if max_size is None:26 max_size = min_size27 self.max_size = max_size28 def __call__(self, image, target):29 size = random.randint(self.min_size, self.max_size)30 image = F.resize(image, size)31 target = F.resize(target, size, interpolation=Image.NEAREST)32 return image, target33class RandomHorizontalFlip(object):34 def __init__(self, flip_prob):35 self.flip_prob = flip_prob36 def __call__(self, image, target):37 if random.random() < self.flip_prob:38 image = F.hflip(image)39 target = F.hflip(target)40 return image, target41class RandomCrop(object):42 def __init__(self, size, fill_with=255):43 self.size = size44 self.fill_with = fill_with45 def __call__(self, image, target):46 image = pad_if_smaller(image, self.size)47 target = pad_if_smaller(target, self.size, fill=self.fill_with)48 crop_params = T.RandomCrop.get_params(image, (self.size, self.size))49 image = F.crop(image, *crop_params)50 target = F.crop(target, *crop_params)51 return image, target52class RandomRotate(object):53 def __init__(self, degrees, fill_with=255):54 self.degrees = degrees55 self.fill_with = fill_with56 def __call__(self, image, target):57 #image = pad_if_smaller(image, self.size)58 #target = pad_if_smaller(target, self.size, fill=self.fill_with)59 angle = T.RandomRotation.get_params(degrees=self.degrees) # image, (self.size, self.size))60 image = F.rotate(image, angle) # crop(image, *crop_params)61 target = F.rotate(img=target, angle=angle, fill=None)62 return image, target63class CenterCrop(object):64 def __init__(self, size):65 self.size = size66 def __call__(self, image, target):67 image = F.center_crop(image, self.size)68 target = F.center_crop(target, self.size)69 return image, target70class ColorJitter(T.ColorJitter):71 def __call__(self, img, mask):72 transform = self.get_params(self.brightness, self.contrast,73 self.saturation, self.hue)74 return transform(img), mask75class ToTensor(object):76 def __call__(self, image, target):77 image = F.to_tensor(image)78 target = torch.as_tensor(np.asarray(target), dtype=torch.int64)79 return image, target80class Normalize(object):81 def __init__(self, mean, std):82 self.mean = mean83 self.std = std84 def __call__(self, image, target):85 image = F.normalize(image, mean=self.mean, std=self.std)...

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