Make image to inputable to model


I tried to load the image and make it inputable to the model.

cracks_guess = []

def check(arr_img):
    with torch.no_grad():
        for idx,img in enumerate(arr_img):
            img = torch.tensor(img).type(torch.FloatTensor).cuda()
            img = img.permute(2,0,1)
            img = img.unsqueeze(0)
            output = net(img)
            output = torch.sigmoid(output)
            pt = torch.round(output)
            if pt==1:
            #if output > 0.3:

is this right way to change the img shape to inputable to model?

Hey, what exactly is the error you are facing. Looks like you have the input images as an array. Dont see any problem there. If your data is too big to have it loaded into one array. You could loops over the path and load one at a time.

This works and you are predicting one at a time.

  • You could also just pass the whole array of dim [n_samples, n_channels, height, width] if data fits into memory or iterate over few samples at one.
  • or just write a dataset and dataloader, and change batchsize to load and compute many samples at once efficiently.

I hope this answers

I’m not facing some error but just make sure this is the right way to put input image.

afterl I collect my data I try to visualize the image like

imgA = cracks_guess[0]

imgA = imgA.detach().cpu()

imgA = imgA.squeeze(0)


imgA = imgA.permute(1,2,0)


but can not see the image

Why do you squeeze? Is the output shape CHW? If so plot should would

why did you pass the images indiviually to the network? You can pass all the images in together and get the result. If you cannot see any image please check if your cracks_guess array is empty.
I personally would pass in all my images together, get output of a binary classifier network and then loop through the outputs to see if thy are 1 or not(append the respective image having +ve prediction in cracks_guess)