Skip to content

Commit

Permalink
fix: save image
Browse files Browse the repository at this point in the history
  • Loading branch information
juheesvt committed Feb 21, 2021
1 parent 7574190 commit 0034b46
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,30 @@ def parse_args(args) -> argparse:
return parser.parse_args(args)


def config(model: str) -> DefaultPredictor():
def config(model: str) -> DefaultPredictor:
cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file(model))
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url(model)
return DefaultPredictor(cfg), cfg


def inference(image_path: str, save_path: str, predictor: DefaultPredictor(), cfg: get_cfg()) -> None:
def inference(image_path: str, save_path: str, predictor: DefaultPredictor, cfg: get_cfg) -> None:
images = glob(image_path + '/*')

for image in images:
try:
read_img = cv2.imread(image)
img_name = image.split("/")[-1]
read_img = cv2.imread(image)
img_name = image.split("/")[-1]

# inference
outputs = predictor(read_img)

# inference
outputs = predictor(read_img)
# Visualization
v = Visualizer(read_img[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2)
out = v.draw_instance_predictions(outputs["instances"].to("cpu"))

# Visualization
v = Visualizer(read_img[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2)
out = v.draw_instance_predictions(outputs["instances"].to("cpu"))
# save image
cv2.imwrite(save_path + "/" + img_name, out.get_image()[:, :, ::-1])

# save image
save_path = os.path.join(save_path + "/" + img_name)
cv2.imwrite(save_path, out.get_image()[:, :, ::-1])
except:
pass

def main(args=None):

Expand All @@ -82,4 +79,4 @@ def main(args=None):


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

0 comments on commit 0034b46

Please sign in to comment.