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

Fix handling of filenames with non-ascii characters #212

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from midas.model_loader import default_models, load_model

first_execution = True


def process(device, model, model_type, image, input_size, target_size, optimize, use_camera):
"""
Run the inference and interpolate.
Expand Down Expand Up @@ -142,8 +144,9 @@ def run(input_path, output_path, model_path, model_type="dpt_beit_large_512", op
if output_path is None:
print("Warning: No output path specified. Images will be processed but not shown or stored anywhere.")
for index, image_name in enumerate(image_names):
image_name = image_name.encode('utf-8', 'surrogateescape').decode('utf-8')

print(" Processing {} ({}/{})".format(image_name, index + 1, num_images))
print(" Processing {} ({}/{})".format(image_name.encode('utf-8'), index + 1, num_images))

# input
original_image_rgb = utils.read_image(image_name) # in [0, 1]
Expand Down Expand Up @@ -264,7 +267,6 @@ def run(input_path, output_path, model_path, model_type="dpt_beit_large_512", op

args = parser.parse_args()


if args.model_weights is None:
args.model_weights = default_models[args.model_type]

Expand Down
5 changes: 3 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def write_pfm(path, image, scale=1):
scale (int, optional): Scale. Defaults to 1.
"""

with open(path, "wb") as file:
with open(path.encode('utf-8'), "wb") as file:
color = None

if image.dtype.name != "float32":
Expand Down Expand Up @@ -163,6 +163,7 @@ def resize_depth(depth, width, height):

return depth_resized


def write_depth(path, depth, grayscale, bits=1):
"""Write depth map to png file.

Expand All @@ -175,7 +176,7 @@ def write_depth(path, depth, grayscale, bits=1):
bits = 1

if not np.isfinite(depth).all():
depth=np.nan_to_num(depth, nan=0.0, posinf=0.0, neginf=0.0)
depth = np.nan_to_num(depth, nan=0.0, posinf=0.0, neginf=0.0)
print("WARNING: Non-finite depth values present")

depth_min = depth.min()
Expand Down