How to use log_input method in grail

Best Python code snippet using grail_python

app.py

Source:app.py Github

copy

Full Screen

...24 query=APP.local_stack.query25 self.finder = FIND_TICKET(query)26 time.sleep(1)27 while not APP.local_stack.mission:28 log_input(APP.local_stack.user["user_name"],"获取任务,开始查询")29 #查询前检查时间30 APP.myclock.check_clock(APP.local_stack.user["user_name"])31 missions = self.finder()32 if missions:33 for mission in missions:34 APP.local_stack.mission.append(mission)35 log_input(APP.local_stack.user["user_name"],"完成一次查询,发现符合要求的车票")36 else:37 log_input(APP.local_stack.user["user_name"],"完成一次查询,未发现符合要求的车票")38 time.sleep(random.randrange(5, 10))39 def execute_mission(self):40 #当查询器获取符合任务需求的票据信息时,进行买票操作41 mission=APP.local_stack.mission.pop()42 try:43 APP.myclock.check_clock(APP.local_stack.user["user_name"])44 res =self.buyer.buy_ticket(mission)45 except:46 self.buyer.driver.close()47 raise Exception("买票失败,未知错误,请联系作者")48 return res49 @classmethod50 def start_mission(cls,user,query):51 app=cls(user,query)52 APP.local_stack.user=user53 APP.local_stack.query=query54 log_input(APP.local_stack.user["user_name"], "初始化浏览器")55 try:56 app.buyer=BUY_TICKET(user,query)57 except:58 raise Exception("浏览器初始化失败")59 log_input(APP.local_stack.user["user_name"], "浏览器初始化成功,买手就位")60 APP.local_stack.mission = []61 while True:62 try:63 app.get_mission()64 except:65 log_input(APP.local_stack.user["user_name"], "查询失败")66 raise Exception("查询失败")67 log_input(APP.local_stack.user["user_name"],"开始买票")68 res = app.execute_mission()69 if res == "succeeded":70 log_input(APP.local_stack.user["user_name"],"买票成功,请在30分钟内进入12306app付款")71 log_input(APP.local_stack.user["user_name"], "任务结束,退出线程")72 break73 else:74 app.buyer.driver.close()75 log_input(APP.local_stack.user["user_name"],"买票失败,再次尝试买票")76 log_input(APP.local_stack.user["user_name"], "重启浏览器")77 try:78 app.buyer = BUY_TICKET(user, query)79 except:80 raise Exception("浏览器初始化失败")81 log_input(APP.local_stack.user["user_name"], "浏览器初始化成功,买手就位")82 APP.local_stack.mission = []83 @classmethod84 def start(cls,users,querys):85 APP.checker.check_before_start(users,querys)86 APP.users=users87 APP.querys=querys88 if len(users)==1:89 user = users[0]90 query=querys.get(user['user_name'])91 log_input(user["user_name"], "*" * 120)92 log_input(user["user_name"], "程序启动")93 log_input(user["user_name"], "载入用户")94 cls.start_mission(user,query)95 return None96 else:97 thread_list=[]98 for user in APP.users:99 log_input(user["user_name"], "*"*120)100 log_input(user["user_name"], "程序启动")101 log_input(user["user_name"], "载入用户,开启线程")102 query=querys.get(user["user_name"])103 t=threading.Thread(target=cls.start_mission,args=(user,query))104 t.start()105 thread_list.append(t)106 time.sleep(1)107 for t in thread_list:108 t.join()...

Full Screen

Full Screen

loss_functions.py

Source:loss_functions.py Github

copy

Full Screen

1import torch2import math3def log_poisson_loss(targets, log_input, compute_full_loss=False):4 """Computes log Poisson loss given `log_input`.5 FOLLOWS TF IMPLEMENTATION6 Gives the log-likelihood loss between the prediction and the target under the7 assumption that the target has a Poisson distribution.8 Caveat: By default, this is not the exact loss, but the loss minus a9 constant term [log(z!)]. That has no effect for optimization, but10 does not play well with relative loss comparisons. To compute an11 approximation of the log factorial term, specify12 compute_full_loss=True to enable Stirling's Approximation.13 For brevity, let `c = log(x) = log_input`, `z = targets`. The log Poisson14 loss is15 -log(exp(-x) * (x^z) / z!)16 = -log(exp(-x) * (x^z)) + log(z!)17 ~ -log(exp(-x)) - log(x^z) [+ z * log(z) - z + 0.5 * log(2 * pi * z)]18 [ Note the second term is the Stirling's Approximation for log(z!).19 It is invariant to x and does not affect optimization, though20 important for correct relative loss comparisons. It is only21 computed when compute_full_loss == True. ]22 = x - z * log(x) [+ z * log(z) - z + 0.5 * log(2 * pi * z)]23 = exp(c) - z * c [+ z * log(z) - z + 0.5 * log(2 * pi * z)]24 Args:25 targets: A `Tensor` of the same type and shape as `log_input`.26 log_input: A `Tensor` of type `float32` or `float64`.27 compute_full_loss: whether to compute the full loss. If false, a constant28 term is dropped in favor of more efficient optimization.29 name: A name for the operation (optional).30 Returns:31 A `Tensor` of the same shape as `log_input` with the componentwise32 logistic losses.33 Raises:34 ValueError: If `log_input` and `targets` do not have the same shape.35 """36 try:37 assert (targets.size() == log_input.size())38 except ValueError:39 raise ValueError(40 "log_input and targets must have the same shape (%s vs %s)" %41 (log_input.size(), targets.size()))42 result = torch.exp(log_input) - log_input * targets43 if compute_full_loss:44 point_five = 0.545 two_pi = 2 * math.pi46 stirling_approx = (targets * torch.log(targets)) - targets + \47 (point_five * torch.log(two_pi * targets))48 zeros = torch.zeros_like(targets, dtype=targets.dtype)49 ones = torch.ones_like(targets, dtype=targets.dtype)50 cond = (targets >= zeros) & (targets <= ones)51 result += torch.where(cond, zeros, stirling_approx)...

Full Screen

Full Screen

module.py

Source:module.py Github

copy

Full Screen

1import cv2 as cv2import random3import tensorflow as tf4import numpy as np5from cv2.ximgproc import guidedFilter678def decomposition(input):9 # 1. Logarithm10 log_input = np.log(input + 1e-6)1112 # 2. Scale to [0,1]13 log_input = (log_input - log_input.min() + 1e-6) / (log_input.max() - log_input.min() + 1e-6)1415 # 3. Guided filter16 base = guidedFilter(log_input.astype('single'), log_input.astype('single'), radius=3, eps=0.1)1718 # 4. Decomposition19 detail = log_input - base2021 return base, detail222324def decomposition_NotLog(input):25 # 1. Logarithm26 # log_input = np.log(input + 1e-6)2728 # 2. Scale to [0,1]29 # log_input = (log_input - log_input.min() + 1e-6) / (log_input.max() - log_input.min() + 1e-6)3031 # 3. Guided filter32 base = guidedFilter(input.astype('single'), input.astype('single'), radius=3, eps=0.1)3334 # 4. Decomposition35 detail = input - base3637 return base, detail3839def randomCropHL(img, img2, width, height):40 if img.shape[0] < height or img.shape[1] < width:41 img = cv.resize(img, dsize=(width, height))42 img2 = cv.resize(img2, dsize=(width, height))43 else:44 x = random.randint(np.round((img.shape[1] - width)/2.1), np.round((img.shape[1] - width)*1.1/2.1))45 y = random.randint(np.round((img.shape[0] - height)/2.1), np.round((img.shape[0] - height)*1.1/2.1))46 img = img[y:y + height, x:x + width]47 img2 = img2[y:y + height, x:x + width]48 return img, img2495051def randomCrop(img, width, height):52 if img.shape[0] < height or img.shape[1] < width:53 img = cv.resize(img, dsize=(width, height))54 else:55 x = random.randint(0, img.shape[1] - width)56 y = random.randint(0, img.shape[0] - height)57 img = img[y:y + height, x:x + width]58 return img596061def ref_padding(tensor, pad_size=1):62 output = tf.pad(tensor, [[0, 0], [pad_size, pad_size], [pad_size, pad_size], [0, 0]], "REFLECT") ...

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