Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug and Fix: Memory Leakage #41

Merged
merged 2 commits into from
Dec 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions extract_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ def setup(args):
default_setup(cfg, args)
return cfg

@ray.remote
def generate_npz(extract_mode, pba: ActorHandle, *args):
def generate_npz(extract_mode, *args):
if extract_mode == 1:
save_roi_features(*args)
elif extract_mode == 2:
Expand All @@ -80,7 +79,6 @@ def generate_npz(extract_mode, pba: ActorHandle, *args):
save_roi_features_by_bbox(*args)
else:
print('Invalid Extract Mode! ')
pba.update.remote(1)

@ray.remote(num_gpus=1)
def extract_feat(split_idx, img_list, cfg, args, actor: ActorHandle):
Expand All @@ -93,7 +91,6 @@ def extract_feat(split_idx, img_list, cfg, args, actor: ActorHandle):
)
model.eval()

generate_npz_list = []
for im_file in (img_list):
if os.path.exists(os.path.join(args.output_dir, im_file.split('.')[0]+'.npz')):
actor.update.remote(1)
Expand All @@ -117,18 +114,18 @@ def extract_feat(split_idx, img_list, cfg, args, actor: ActorHandle):
features_pooled = [feat.cpu() for feat in features_pooled]
if not attr_scores is None:
attr_scores = [attr_score.cpu() for attr_score in attr_scores]
generate_npz_list.append(generate_npz.remote(1, actor,
generate_npz(1,
args, cfg, im_file, im, dataset_dict,
boxes, scores, features_pooled, attr_scores))
boxes, scores, features_pooled, attr_scores)
# extract bbox only
elif cfg.MODEL.BUA.EXTRACTOR.MODE == 2:
with torch.set_grad_enabled(False):
boxes, scores = model([dataset_dict])
boxes = [box.cpu() for box in boxes]
scores = [score.cpu() for score in scores]
generate_npz_list.append(generate_npz.remote(2, actor,
generate_npz(2,
args, cfg, im_file, im, dataset_dict,
boxes, scores))
boxes, scores)
# extract roi features by bbox
elif cfg.MODEL.BUA.EXTRACTOR.MODE == 3:
if not os.path.exists(os.path.join(args.bbox_dir, im_file.split('.')[0]+'.npz')):
Expand All @@ -150,11 +147,11 @@ def extract_feat(split_idx, img_list, cfg, args, actor: ActorHandle):
features_pooled = [feat.cpu() for feat in features_pooled]
if not attr_scores is None:
attr_scores = [attr_score.data.cpu() for attr_score in attr_scores]
generate_npz_list.append(generate_npz.remote(3, actor,
generate_npz(3,
args, cfg, im_file, im, dataset_dict,
boxes, scores, features_pooled, attr_scores))
boxes, scores, features_pooled, attr_scores)

ray.get(generate_npz_list)
actor.update.remote(1)


def main():
Expand Down Expand Up @@ -238,4 +235,4 @@ def main():
ray.get(actor.get_counter.remote())

if __name__ == "__main__":
main()
main()