Add compatibility with pifpaf 0.9 (#9)
* remove dependancy on pifpaf.transform * add compatibility with pifpaf 0.9 * change verbose output * add image transform compatible with webcam
This commit is contained in:
parent
63e5e5ef2c
commit
f23a2e34f5
@ -136,9 +136,9 @@ Multiple visualizations can be combined in different windows.
|
||||
|
||||
The above gif has been obtained running on a Macbook the command:
|
||||
|
||||
`pip3 install opencv-python`
|
||||
|
||||
`python3 -m monoloco.run predict --webcam --scale 0.2 --output_types combined --z_max 10 --checkpoint resnet50`
|
||||
```pip3 install opencv-python
|
||||
python3 -m monoloco.run predict --webcam --scale 0.2 --output_types combined --z_max 10 --checkpoint resnet50 --model data/models/monoloco-190513-1437.pkl
|
||||
```
|
||||
|
||||
# Preprocess
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
|
||||
"""Open implementation of MonoLoco."""
|
||||
|
||||
__version__ = '0.4.3'
|
||||
__version__ = '0.4.4'
|
||||
|
||||
@ -347,7 +347,7 @@ class EvalKitti:
|
||||
def show_statistics(self):
|
||||
|
||||
print('-'*90)
|
||||
alp = [[str(100 * average(self.errors[key][perc]))[:4]
|
||||
alp = [[str(100 * average(self.errors[key][perc]))[:5]
|
||||
for perc in ['<0.5m', '<1m', '<2m']]
|
||||
for key in self.METHODS]
|
||||
|
||||
@ -373,8 +373,8 @@ class EvalKitti:
|
||||
if key == 'our':
|
||||
print("% of annotation inside the confidence interval: {:.1f} %, "
|
||||
"of which {:.1f} % at higher risk"
|
||||
.format(self.dic_stats['test'][key][clst]['interval'],
|
||||
self.dic_stats['test'][key][clst]['at_risk']))
|
||||
.format(self.dic_stats['test'][key][clst]['interval']*100,
|
||||
self.dic_stats['test'][key][clst]['at_risk']*100))
|
||||
|
||||
for perc in ['<0.5m', '<1m', '<2m']:
|
||||
print("{} Instances with error {}: {:.2f} %"
|
||||
|
||||
@ -5,22 +5,18 @@ import numpy as np
|
||||
import torchvision
|
||||
import torch
|
||||
from PIL import Image, ImageFile
|
||||
|
||||
from openpifpaf.network import nets
|
||||
from openpifpaf import decoder
|
||||
from openpifpaf import transforms
|
||||
|
||||
from .process import image_transform
|
||||
|
||||
|
||||
class ImageList(torch.utils.data.Dataset):
|
||||
"""It defines transformations to apply to images and outputs of the dataloader"""
|
||||
def __init__(self, image_paths, scale, image_transform=None):
|
||||
def __init__(self, image_paths, scale):
|
||||
self.image_paths = image_paths
|
||||
self.image_transform = image_transform or transforms.image_transform # to_tensor + normalize (from pifpaf)
|
||||
self.scale = scale
|
||||
|
||||
# data = datasets.ImageList(args.images, preprocess=transforms.RescaleRelative(2
|
||||
# .0)
|
||||
|
||||
def __getitem__(self, index):
|
||||
image_path = self.image_paths[index]
|
||||
ImageFile.LOAD_TRUNCATED_IMAGES = True
|
||||
@ -34,7 +30,7 @@ class ImageList(torch.utils.data.Dataset):
|
||||
interpolation=Image.BICUBIC)
|
||||
# PIL images are not iterables
|
||||
original_image = torchvision.transforms.functional.to_tensor(image) # 0-255 --> 0-1
|
||||
image = self.image_transform(image)
|
||||
image = image_transform(image)
|
||||
|
||||
return image_path, original_image, image
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@ import json
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
import torchvision
|
||||
|
||||
from ..utils import get_keypoints, pixel_to_camera
|
||||
|
||||
@ -82,18 +83,6 @@ def laplace_sampling(outputs, n_samples):
|
||||
return xx
|
||||
|
||||
|
||||
def epistemic_variance(total_outputs):
|
||||
"""Compute epistemic variance"""
|
||||
|
||||
# var_y = np.sum(total_outputs**2, axis=0) / total_outputs.shape[0] - (np.mean(total_outputs, axis=0))**2
|
||||
var_y = np.var(total_outputs, axis=0)
|
||||
lower_b = np.quantile(a=total_outputs, q=0.25, axis=0)
|
||||
upper_b = np.quantile(a=total_outputs, q=0.75, axis=0)
|
||||
var_new = (upper_b - lower_b)
|
||||
|
||||
return var_y, var_new
|
||||
|
||||
|
||||
def unnormalize_bi(outputs):
|
||||
"""Unnormalize relative bi of a nunmpy array"""
|
||||
|
||||
@ -151,3 +140,13 @@ def prepare_pif_kps(kps_in):
|
||||
ccs = kps_in[2:][::3]
|
||||
|
||||
return [xxs, yys, ccs]
|
||||
|
||||
|
||||
def image_transform(image):
|
||||
|
||||
normalize = torchvision.transforms.Normalize(
|
||||
mean=[0.485, 0.456, 0.406],
|
||||
std=[0.229, 0.224, 0.225]
|
||||
)
|
||||
transforms = torchvision.transforms.Compose([torchvision.transforms.ToTensor(), normalize, ])
|
||||
return transforms(image)
|
||||
|
||||
@ -11,12 +11,11 @@ import time
|
||||
import torch
|
||||
import matplotlib.pyplot as plt
|
||||
from PIL import Image
|
||||
from openpifpaf import transforms
|
||||
import cv2
|
||||
|
||||
from ..visuals import Printer
|
||||
from ..network import PifPaf, MonoLoco
|
||||
from ..network.process import preprocess_pifpaf, factory_for_gt
|
||||
from ..network.process import preprocess_pifpaf, factory_for_gt, image_transform
|
||||
|
||||
|
||||
def webcam(args):
|
||||
@ -42,7 +41,7 @@ def webcam(args):
|
||||
height, width, _ = image.shape
|
||||
print('resized image size: {}'.format(image.shape))
|
||||
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
||||
processed_image_cpu = transforms.image_transform(image.copy())
|
||||
processed_image_cpu = image_transform(image.copy())
|
||||
processed_image = processed_image_cpu.contiguous().to(args.device, non_blocking=True)
|
||||
fields = pifpaf.fields(torch.unsqueeze(processed_image, 0))[0]
|
||||
_, _, pifpaf_out = pifpaf.forward(image, processed_image_cpu, fields)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user