Files
HSAP/algorithms/lane_ufld/code.embedded.bak/pytorch-auto-drive-master/utils/common.py
Chengfang Lu e72bc061c5 feat: HSAP platform v2 — modular navigation, quality review, audit log, world model simulation
Major changes:
- New frontend (platform/web/): Vite + React 18 + TypeScript + Tailwind
- 4-module navigation: 数据送标 / 模型管理 / 车队管理 / 系统管理
- Data catalog with charts (DMS/ADAS/Lane 3-tab view)
- Quality review workflow (标注质检): Good/Fine/Bad scoring with auto-advance
- Audit enhancements: batch operations, rejection categories, Feishu notifications
- Operation audit log (操作日志)
- World model simulation studio (仿真工坊)
- Dataset version management with snapshots and diff
- ADAS 7-class dataset integration (138K images organized + compressed)
- User management with Feishu integration and pagination
- CRUD/search/filter on all pages, card layout redesign
- PIL-optimized image overlay rendering
- Auto-snapshot on build, in_review workflow stage
- Removed embedded algorithm code (now in workspace)
2026-06-03 11:40:21 +08:00

70 lines
2.5 KiB
Python

import torch
from collections import OrderedDict
from .ddp_utils import save_on_master
def get_warnings():
# Get rid of the extra line of code printing
# https://stackoverflow.com/a/26433913/15449902
import warnings
def warning_on_one_line(message, category, filename, lineno, file=None, line=None):
return '%s:%s: %s: %s\n' % (filename, lineno, category.__name__, message)
warnings.formatwarning = warning_on_one_line
return warnings
warnings = get_warnings()
# Save model checkpoints (supports amp)
def save_checkpoint(net, optimizer, lr_scheduler, filename='temp.pt'):
checkpoint = {
'model': net.state_dict(),
'optimizer': optimizer.state_dict() if optimizer is not None else None,
'lr_scheduler': lr_scheduler.state_dict() if lr_scheduler is not None else None
}
save_on_master(checkpoint, filename)
# Load model checkpoints (supports amp)
def load_checkpoint(net, optimizer, lr_scheduler, filename, strict=True):
try:
checkpoint = torch.load(filename, map_location='cpu')
except:
warnings.warn('Model not saved as on cpu, could be a legacy trained weight, trying loading on saved device...')
checkpoint = torch.load(filename)
print('Loaded on saved device.')
# To keep BC while having a acceptable variable name for lane detection
checkpoint['model'] = OrderedDict((k.replace('aux_head', 'lane_classifier') if 'aux_head' in k else k, v)
for k, v in checkpoint['model'].items())
# state_dict = checkpoint['model']
# self_state_dict = net.state_dict()
# self_keys = list(self_state_dict.keys())
# for i, (_, v) in enumerate(state_dict.items()):
# if i > len(self_keys) - 1:
# break
# self_state_dict[self_keys[i]] = v
#
# # for k, v in state_dict.items():
# # print(k)
# # quit(0)
net.load_state_dict(checkpoint['model'], strict=strict)
if optimizer is not None:
try: # Shouldn't be necessary, but just in case
optimizer.load_state_dict(checkpoint['optimizer'])
except RuntimeError:
warnings.warn('Incorrect optimizer state dict, maybe you are using old code with aux_head?')
pass
if lr_scheduler is not None:
try: # Shouldn't be necessary, but just in case
lr_scheduler.load_state_dict(checkpoint['lr_scheduler'])
except RuntimeError:
warnings.warn('Incorrect lr scheduler state dict, maybe you are using old code with aux_head?')
pass