Skip to content

Commit edd0258

Browse files
committed
add adabins and yolo
1 parent 73d32ae commit edd0258

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+4545
-84
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,4 @@ dmypy.json
128128
# Pyre type checker
129129
.pyre/
130130

131-
res/models
131+
res/*

.vscode/settings.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"python.linting.pylintArgs": [
3+
"--generated-members=numpy.* ,torch.*"
4+
],
5+
"python.linting.pylintEnabled": false,
6+
"python.linting.flake8Enabled": true,
7+
"python.linting.enabled": true
8+
}

__init__.py

Whitespace-only changes.

adabins.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#%%
21
from models.adabins.infer import InferenceHelper
3-
import matplotlib.pyplot as plt
42
from time import time
53
import cv2
64
from PIL import Image
5+
import torch
76

87
# img = Image.open("test_imgs/classroom__rgb_00283.jpg")
98
start = time()
@@ -12,14 +11,12 @@
1211
cap = cv2.VideoCapture('https://192.168.0.164:8080/video')
1312
while True:
1413
ret, frame = cap.read()
15-
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
14+
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)/255
1615

1716
im_pil = Image.fromarray(frame)
1817
# tgt_img = load_tensor_image( dataset_dir + test_files[j], args)
1918
centers, pred = inferHelper.predict_pil(im_pil)
20-
depth_img = pred[0,0]
21-
print(depth_img.shape)
22-
print(1/depth_img)
19+
depth_img = pred[0, 0]/10
2320
cv2.imshow('frame', depth_img)
2421
if cv2.waitKey(1) & 0xFF == ord('q'):
2522
break
File renamed without changes.

models/adabins/infer.py adabins/infer.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from torchvision import transforms
99
from tqdm import tqdm
1010

11-
import models.adabins.model_io as model_io
12-
import models.adabins.utils as utils
13-
from models.adabins.models import UnetAdaptiveBins
11+
import adabins.model_io as model_io
12+
import adabins.utils as utils
13+
from adabins.models import UnetAdaptiveBins
1414

1515

1616
def _is_pil_image(img):
@@ -72,7 +72,7 @@ def __init__(self, dataset='nyu', device='cuda:0'):
7272
self.max_depth = 10
7373
self.saving_factor = 1000 # used to save in 16 bit
7474
model = UnetAdaptiveBins.build(n_bins=256, min_val=self.min_depth, max_val=self.max_depth)
75-
pretrained_path = "./res/models/adabins_nyu.pt"
75+
pretrained_path = "./res/weights/adabins_nyu.pt"
7676
elif dataset == 'kitti':
7777
raise ValueError("dataset can be only 'nyu' {}".format(dataset))
7878
self.min_depth = 1e-3
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

densedepth.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from matplotlib import pyplot as plt
2+
from utils import predict, load_images, display_images
3+
from layers import BilinearUpSampling2D
4+
from keras.models import load_model
5+
import os
6+
import glob
7+
import argparse
8+
import matplotlib
9+
10+
# Keras / TensorFlow
11+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '5'
12+
13+
# Argument Parser
14+
parser = argparse.ArgumentParser(
15+
description='High Quality Monocular Depth Estimation via Transfer Learning')
16+
parser.add_argument('--model', default='nyu.h5', type=str,
17+
help='Trained Keras model file.')
18+
parser.add_argument('--input', default='examples/*.png',
19+
type=str, help='Input filename or folder.')
20+
args = parser.parse_args()
21+
22+
# Custom object needed for inference and training
23+
custom_objects = {'BilinearUpSampling2D': BilinearUpSampling2D,
24+
'depth_loss_function': None}
25+
26+
print('Loading model...')
27+
28+
# Load model into GPU / CPU
29+
model = load_model(args.model, custom_objects=custom_objects, compile=False)
30+
31+
print('\nModel loaded ({0}).'.format(args.model))
32+
33+
# Input images
34+
inputs = load_images(glob.glob(args.input))
35+
print('\nLoaded ({0}) images of size {1}.'.format(
36+
inputs.shape[0], inputs.shape[1:]))
37+
38+
# Compute results
39+
outputs = predict(model, inputs)
40+
41+
# matplotlib problem on ubuntu terminal fix
42+
# matplotlib.use('TkAgg')
43+
44+
# Display results
45+
viz = display_images(outputs.copy(), inputs.copy())
46+
plt.figure(figsize=(10, 5))
47+
plt.imshow(viz)
48+
plt.savefig('test.png')
49+
plt.show()
50+
51+
52+
if __name__ == '__main__':
53+
parser = argparse.ArgumentParser()
54+
parser.add_argument('--weights', nargs='+', type=str,
55+
default='res/weights/yolov3.pt', help='model.pt path(s)')
56+
# file/folder, 0 for webcam
57+
parser.add_argument('--source', type=str,
58+
default='data/images', help='source')
59+
opt = parser.parse_args()
60+
print(opt)

0 commit comments

Comments
 (0)