How to make gaussian distribution in pytorch?
I want to make probability like
torch.bernoulli()
this function. Has any solution?
do you know?
how many words do you know
See also questions close to this topic
-
python screengrab problem (on yolov5, pytorch)
im trying to get a screenshot of a window as fast and then inference on yolov5 it works but sometimes it doesnt detect very well compared to using detect.py on the same image. i think its probably because of img shape or array but i dont know where or how to edit those to make it work. can anyone help me with this please?
import torch import numpy as np import win32gui import win32ui import win32con w = 800 # set this h = 600 # set this bmpfilenamename = "color.bmp" #set this windowname = 'put windowname' def screenshot(): hwnd = win32gui.FindWindow(None, windowname) wDC = win32gui.GetWindowDC(hwnd) dcObj=win32ui.CreateDCFromHandle(wDC) cDC=dcObj.CreateCompatibleDC() dataBitMap = win32ui.CreateBitmap() dataBitMap.CreateCompatibleBitmap(dcObj, w, h) cDC.SelectObject(dataBitMap) cDC.BitBlt((0,0),(w, h) , dcObj, (0,0), win32con.SRCCOPY) #save the screenshot #dataBitMap.SaveBitmapFile(cDC, bmpfilenamename) signedIntsArray = dataBitMap.GetBitmapBits(True) img = np.frombuffer(signedIntsArray, dtype='uint8') img.shape = (h,w,4) # Free Resources dcObj.DeleteDC() cDC.DeleteDC() win32gui.ReleaseDC(hwnd, wDC) win32gui.DeleteObject(dataBitMap.GetHandle()) #img = img[..., ::-1] #img = np.ascontiguousarray(img) return img #load model = torch.hub.load('./', 'custom', path='yolov5s.pt', source='local') #inference test = screenshot() results = model(test) boxes = results.pandas().xyxy[0] print (boxes)
edit : i figured you can do it by changing the code from this
results = model(test)
to this
results = model(cv.cvtColor(test, cv.COLOR_BGR2RGB))
but isnt this code supposed to do the same? for some reason this one wont work
img[: ,: ,::-1]
-
Pytorch get "reduced" tensor by indices
I have a tensor
a = torch.arange(6).reshape(2,3)
, and another tensorb=(torch.rand(a.size())> 0.5).int().nonzero()
.I want to create a new tensor that contains only values from
a
of the indices that are indicated byb
.For example:
a = torch.arange(6).reshape(2,3) # tensor([[0, 1, 2], # [3, 4, 5]]) b = (torch.rand(a.size())> 0.5).int().nonzero() # tensor([[0, 1], # [0, 2], # [1, 0], # [1, 1]])
The desired output is:
tensor([1,2,3,4])
I know that I can iterate over the values of
b
and access those values ina
as indices but I wanted to know if there is a betterPytorch
way to to this (using tensor operations only).** The shape of the output tensor doesn't really matter, I just need to have a tensor with only the values indicated by
b
. -
Print accuracy for YOLOv5 model?
I want to print the accuracy of my trained model. I do understand when I use the model through the camera it shows me the accuracy on the box only, but I want to see the accuracy of my whole model rather than a single instance of my image.
cap = cv2.VideoCapture(0) # loop through labels for label in labels: print('Collecting images for {}'.format(label)) #so that we can see when transitioning through images time.sleep(5) #sleep or wait for 5 seconds when transitioning between image for other class # Loop through image range for img_num in range(number_imgs): print('Collecting images for {}, image number {}'.format(label, img_num)) # webcam feed ret, frame = cap.read() # read the feed from the web cam and store it in given vars # Naming image path imgname = os.path.join(IMAGES_PATH, label+'.'+str(uuid.uuid1())+'.jpg') #Writes out image to file cv2.imwrite(imgname,frame) # Render to screen cv2.imshow('Image Collection', frame) # 2 sec delay between diff captures time.sleep(2) if cv2.waitKey(10) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
!cd yolov5 && python train.py --img 320 --batch 16 --epochs 500 --data dataset.yml --weights yolov5s.pt
model = torch.hub.load('ultralytics/yolov5', 'custom', path='yolov5/runs/train/exp/weights/last.pt', force_reload=True) while cap.isOpened(): ret, frame = cap.read() # Make detections results = model(frame) cv2.imshow('YOLO', np.squeeze(results.render())) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows() cv2.waitKey(1)
-
Pdf of product of two i.i.d random variable distributed as circular symmetric gaussian
what is a distribution of the product of two circular symmetric Gaussian random variables?
-
How to draw a plot with srveral Gaussuans without any data in Python?
So, I wanna do a spectrum with 4 lines described as gaussian fuctions. I know only their x and y and know how it's supposed to look, but have no data. How do I do a dataset for this plot so that would be arrays for x and y axes? The plot has to look like that: enter image description here