| from ultralytics import YOLO |
| import torch |
| import math |
|
|
| |
| model = YOLO('yolov8n.pt') |
|
|
| |
| state_dict = model.state_dict() |
|
|
| |
| flattened_params = [torch.flatten(param) for param in state_dict.values()] |
|
|
| |
| merged_params = torch.cat(flattened_params) |
|
|
| |
| total_elements = merged_params.numel() |
| print(f"Total elements: {total_elements}") |
|
|
| |
| square_size = math.ceil(total_elements ** 0.5) |
| total_required_elements = square_size ** 2 |
|
|
| |
| if total_required_elements > total_elements: |
| padding = total_required_elements - total_elements |
| |
| merged_params = torch.cat([merged_params, torch.full((padding,), -1)]) |
|
|
| |
| square_matrix = merged_params.view(square_size, square_size) |
|
|
| |
| print(f"Reshaped into square matrix: {square_matrix.shape}") |
| print(square_matrix) |
|
|