HTTPS POST to query FastAPI using python requests

I am trying to serve a Neural Network using FastAPI. from fastapi import Depends, FastAPI from pydantic import BaseModel from typing import Dict class iRequest(BaseModel): arg1: str arg2: str …

Torch: Why is this collate function so much faster than this other one?

I have developed two collate functions to read in data from h5py files (I tried to create some synthetic data for a MWE here but it is not going to plan). The difference between the two in processing …

Why do sometimes CNN models predict just one class out of all others?

I am relatively new to the deep learning landscape, so please don’t be as mean as Reddit! It seems like a general question so I won’t be giving my code here as it doesn’t seem necessary (if it is, …

Why is the code not able to approximate the square function?

WHy does the following code not work as a square approximator? I am getting weird dimensions. When I tried plotting loss, the graph somehow does not show anything. I am a beginner with pytorch, so I …

TypeError: expected CPU (got CUDA)

import torch torch.cuda.is_available() torch.cuda.current_device() torch.cuda.get_device_name(0) torch.cuda.memory_reserved() torch.cuda.memory_allocated() torch.cuda.memory_allocated() var1=torch….

Convert 5D tensor to 4D tensor in PyTorch

In PyTorch I have a 5D tensor X of dimensions B x 9 x C x H x W. I want to convert it into a 4D tensor Y with dimensions B x 9C x H x W such that concatenation happens channel wise. To illustrate let, …

Changing batch,height,width,alpha to batch,alpha,height,width for pytorch

I have batch of images like torch.Size([10, 512, 512, 3]) I can loop to the images and can see 10 images. But to feed this batch to pytorch i have to convert it to torch.Size([10, 3, 512, 512]) I …

How to get the last index of model’s prediction?

I am new to PyTorch. I have a variable pred which has a list of a tensor. print(pred) output: [tensor([[176.64380, 193.86154, 273.84702, 306.30405, 0.83492, 2.00000]])] So I wanted to access the last …

BERT DataLoader: Difference between shuffle=True vs Sampler?

I trained a DistilBERT model with DistilBertForTokenClassification on ConLL data fro predicting NER. Training seem to have completed with no problems but I have 2 problems during evaluation phase. I’…

How to understand creating leaf tensors in PyTorch?

From PyTorch documentation: b = torch.rand(10, requires_grad=True).cuda() b.is_leaf False # b was created by the operation that cast a cpu Tensor into a cuda Tensor e = torch.rand(10).cuda()….