training fix.add global settings
This commit is contained in:
@@ -110,60 +110,31 @@ def generate_training_json(training_id):
|
||||
break
|
||||
|
||||
# Construct ABSOLUTE path using data_dir
|
||||
# Detect platform for proper path handling
|
||||
import platform
|
||||
is_windows = platform.system() == 'Windows'
|
||||
# Normalize data_dir - ensure it uses backslashes for Windows
|
||||
normalized_data_dir = data_dir.rstrip('/\\').replace('/', '\\')
|
||||
|
||||
# Normalize path separators in file_name to forward slashes first (OS-agnostic)
|
||||
file_name = file_name.replace('\\', '/')
|
||||
|
||||
# Normalize data_dir to use forward slashes
|
||||
normalized_data_dir = data_dir.rstrip('/\\').replace('\\', '/')
|
||||
|
||||
# Check if file_name is already an absolute path
|
||||
is_absolute = False
|
||||
if is_windows:
|
||||
# Windows: Check for drive letter (C:/) or UNC path (//server/)
|
||||
is_absolute = (len(file_name) > 1 and file_name[1] == ':') or file_name.startswith('//')
|
||||
else:
|
||||
# Linux/Mac: Check for leading /
|
||||
is_absolute = file_name.startswith('/')
|
||||
|
||||
if not is_absolute:
|
||||
# Check if already absolute path
|
||||
if not (file_name.startswith('\\\\') or (len(file_name) > 1 and file_name[1] == ':')):
|
||||
# It's a relative path, combine with data_dir
|
||||
if normalized_data_dir.startswith('//'):
|
||||
# UNC path on Windows
|
||||
file_name = normalized_data_dir + '/' + file_name
|
||||
# For UNC paths, we need to manually concatenate to preserve \\
|
||||
if normalized_data_dir.startswith('\\\\'):
|
||||
# UNC path
|
||||
file_name = normalized_data_dir + '\\' + file_name.replace('/', '\\')
|
||||
else:
|
||||
# Regular path - use os.path.join but with forward slashes
|
||||
file_name = os.path.join(normalized_data_dir, file_name).replace('\\', '/')
|
||||
|
||||
# Final OS-specific normalization
|
||||
if is_windows:
|
||||
# Convert to Windows-style backslashes
|
||||
file_name = file_name.replace('/', '\\')
|
||||
# Regular path
|
||||
file_name = os.path.join(normalized_data_dir, file_name.replace('/', '\\'))
|
||||
else:
|
||||
# Keep as forward slashes for Linux/Mac
|
||||
file_name = file_name.replace('\\', '/')
|
||||
# Already absolute, just normalize separators
|
||||
file_name = file_name.replace('/', '\\')
|
||||
|
||||
# Get annotations for this image
|
||||
annotations = Annotation.query.filter_by(image_id=image.image_id).all()
|
||||
|
||||
# Ensure width and height are integers and valid
|
||||
# If missing or invalid, skip this image or use default dimensions
|
||||
img_width = int(image.width) if image.width else 0
|
||||
img_height = int(image.height) if image.height else 0
|
||||
|
||||
# Skip images with invalid dimensions
|
||||
if img_width <= 0 or img_height <= 0:
|
||||
print(f'Warning: Skipping image {file_name} with invalid dimensions: {img_width}x{img_height}')
|
||||
continue
|
||||
|
||||
coco_images.append({
|
||||
'id': image_id,
|
||||
'file_name': file_name, # Use absolute path
|
||||
'width': img_width,
|
||||
'height': img_height
|
||||
'width': image.width or 0,
|
||||
'height': image.height or 0
|
||||
})
|
||||
|
||||
for annotation in annotations:
|
||||
|
||||
Reference in New Issue
Block a user