Sandeepa/MeshReconstruction3D
0
1import torch2from transformers import GLPNImageProcessor, GLPNForDepthEstimation3from image_resize import resize_img4 5def depth_detection(image, pad=16):6 7 feature_extractor = GLPNImageProcessor.from_pretrained("vinvino02/glpn-nyu")8 model = GLPNForDepthEstimation.from_pretrained("vinvino02/glpn-nyu")9 new_img = resize_img(image)10 inputs = feature_extractor(images=new_img, return_tensors="pt")11 12 with torch.no_grad():13 outputs = model(**inputs)14 predicted_depth = outputs.predicted_depth15 16 output = predicted_depth.squeeze().cpu().numpy() * 1000.017 output = output[pad:-pad, pad:-pad]18 new_image = new_img.crop((pad, pad, new_img.width - pad, new_img.height - pad))19 return new_image,output20 