Skip to content

Commit c373d69

Browse files
committedOct 31, 2022
Removing flow quantization from optical flow scripts. Fixing README.md.
1 parent 231d76c commit c373d69

File tree

3 files changed

+8
-32
lines changed

3 files changed

+8
-32
lines changed
 

‎README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ conda env create --name ssl-vos python=3.8 pip
3838
conda install pytorch torchvision torchaudio cudatoolkit=11.6 -c pytorch -c conda-forge
3939
pip install scikit-learn opencv-python fast_slic imageio matplotlib scikit-image easydict path.py
4040
41-
git clone https://github.com/ylabbe/bullet3.git && cd bullet3
4241
python setup.py build
4342
python setup.py install
4443
```
@@ -55,7 +54,7 @@ in order to prepare rest of your environment.
5554
Our approach requires three steps to run produce segmentations. At first, extract DINO features and optical flows by via
5655
```
5756
python extract_dino_features.py --dataset davis
58-
python generate_flow_arflow.py --dataset davis --step 1 --raw
57+
python generate_flow_arflow.py --dataset davis --step 1
5958
```
6059

6160
The second step consists of extracting the initial eigenvectors, which can be done by

‎generate_flow_arflow.py

+4-15
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
from ARFlow.utils.torch_utils import restore_model
1212
from ARFlow.models.pwclite import PWCLite
13-
from config import DATA_PATH, MAX_FLOW_VAL
14-
from utils.flow_utils import quantize_flow
1513
from ARFlow.utils.warp_utils import flow_warp
14+
from config import DATA_PATH
15+
1616

1717

1818
def calculate_binary_flow_weights(org_img, warped_img, thr_value, thr_type):
@@ -87,12 +87,7 @@ def generate_arflow_flow(args):
8787

8888
binary_weights = calculate_binary_flow_weights(image1, re_image1, args.thr_value, args.thr_type)
8989
flow = flow * binary_weights[:,:,None]
90-
if args.raw:
91-
np.save(flow_folder / imfile1.with_suffix('.npy').name, flow)
92-
else:
93-
dx, dy = quantize_flow(flow, max_val=MAX_FLOW_VAL, norm=False)
94-
flow = np.stack([dx, dy, np.zeros(dx.shape)], axis=-1)
95-
cv2.imwrite((flow_folder / imfile1.name).as_posix(), flow[:, :, [2, 1, 0]])
90+
np.save(flow_folder / imfile1.with_suffix('.npy').name, flow)
9691

9792
images = list(reversed(images))
9893
print(f'Working on folder: {folder.name} in backward direction')
@@ -111,20 +106,14 @@ def generate_arflow_flow(args):
111106

112107
binary_weights = calculate_binary_flow_weights(image1, re_image1, args.thr_value, args.thr_type)
113108
flow = flow * binary_weights[:,:,None]
114-
if args.raw:
115-
np.save(flow_folder_reverse / imfile1.with_suffix('.npy').name, flow)
116-
else:
117-
dx, dy = quantize_flow(flow, max_val=MAX_FLOW_VAL, norm=False)
118-
flow = np.stack([dx, dy, np.zeros(dx.shape)], axis=-1)
119-
cv2.imwrite((flow_folder_reverse / imfile1.name).as_posix(), flow[:, :, [2, 1, 0]])
109+
np.save(flow_folder_reverse / imfile1.with_suffix('.npy').name, flow)
120110

121111
if __name__ == '__main__':
122112
parser = argparse.ArgumentParser()
123113
parser.add_argument('--model', help="restore checkpoint", default='ARFlow/checkpoints/CityScapes/pwclite_ar.tar')
124114
parser.add_argument('--dataset', help="dataset for flow estimation")
125115
parser.add_argument('--step', type=int, default=1, help="flow step size")
126116
parser.add_argument('--test-shape', default=[384, 640], type=int, nargs=2)
127-
parser.add_argument('--raw', action='store_true', help='generate raw optical flow')
128117
parser.add_argument('--thr_type', type=str, default='percentile')
129118
parser.add_argument('--thr_value', type=int, default=90)
130119
args = parser.parse_args()

‎generate_flow_raft.py

+3-15
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
from RAFT.core.raft import RAFT
99
from RAFT.core.utils.utils import InputPadder
1010

11-
from config import DATA_PATH, MAX_FLOW_VAL
12-
from utils.flow_utils import quantize_flow
11+
from config import DATA_PATH
1312

1413

1514
def load_image(imfile):
@@ -59,12 +58,7 @@ def generate_raft_flow(args):
5958

6059
_, flow = model(image1, image2, iters=20, test_mode=True)
6160
flow = flow[0].permute(1, 2, 0).cpu().numpy()
62-
if args.raw:
63-
np.save(flow_folder / imfile1.with_suffix('.npy').name, flow)
64-
else:
65-
dx, dy = quantize_flow(flow, max_val=MAX_FLOW_VAL, norm=False)
66-
flow = np.stack([dx, dy, np.zeros(dx.shape)], axis=-1)
67-
cv2.imwrite((flow_folder / imfile1.name).as_posix(), flow[:, :, [2, 1, 0]])
61+
np.save(flow_folder / imfile1.with_suffix('.npy').name, flow)
6862

6963
images = list(reversed(images))
7064
print(f'Working on folder: {folder.name} in backward direction')
@@ -77,20 +71,14 @@ def generate_raft_flow(args):
7771

7872
_, flow = model(image1, image2, iters=20, test_mode=True)
7973
flow = flow[0].permute(1, 2, 0).cpu().numpy()
80-
if args.raw:
81-
np.save(flow_folder_reverse / imfile1.with_suffix('.npy').name, flow)
82-
else:
83-
dx, dy = quantize_flow(flow, max_val=MAX_FLOW_VAL, norm=False)
84-
flow = np.stack([dx, dy, np.zeros(dx.shape)], axis=-1)
85-
cv2.imwrite((flow_folder_reverse / imfile1.name).as_posix(), flow[:, :, [2, 1, 0]])
74+
np.save(flow_folder_reverse / imfile1.with_suffix('.npy').name, flow)
8675

8776

8877
if __name__ == '__main__':
8978
parser = argparse.ArgumentParser()
9079
parser.add_argument('--model', help="restore checkpoint")
9180
parser.add_argument('--dataset', help="dataset for flow estimation")
9281
parser.add_argument('--step', type=int, default=1, help="flow step size")
93-
parser.add_argument('--raw', action='store_true', help='generate raw optical flow')
9482
parser.add_argument('--small', action='store_true', help='use small model')
9583
parser.add_argument('--mixed_precision', action='store_true', help='use mixed precision')
9684
parser.add_argument('--alternate_corr', action='store_true', help='use efficent correlation implementation')

0 commit comments

Comments
 (0)
Please sign in to comment.