#134·TripoSR

紧急 - 输出不符合高清质量

作者: VijiHithub创建于 2025年3月12日更新于 2026年1月28日

import argparse import logging import os import time import numpy as np import rembg import torch import xatlas from PIL import Image from tsr.system import TSR from tsr.utils import remove_background, resize_foreground, save_video, to_gradio_3d_orientation from tsr.bake_texture import bake_texture from torch.nn.parallel import DistributedDataParallel as DDP print(torch.cuda.is_available(), 'cuda.is_available()') # Should print True class Timer: def init(self): self.items = {} self.time_scale = 1000.0 # ms self.time_unit = "ms" def start(self, name: str) -> None: if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() self.items[name] = time.time() logging.info(f"{name} ...") def end(self, name: str) -> None: if name not in self.items: return if torch.cuda.is_available(): torch.cuda.synchronize() start_time = self.items.pop(name) delta = time.time() - start_time t = delta * self.time_scale logging.info(f"{name} finished in {t:.2f}{self.time_unit}.") timer = Timer() logging.basicConfig( format="%(asctime)s - %(levelname)s - %(message)s", level=logging.INFO ) parser = argparse.ArgumentParser() parser.add_argument("image", type=str, nargs="+", help="Path to input image(s).") parser.add_argument( "device", default="cuda", type=str, help="Device to use. If no CUDA-compatible device is found, will fallback to 'cpu'. Default: 'cuda:0'" ) parser.add_argument( "pretrained-model-name-or-path", default="stabilityai/TripoSR", type=str, help="Path to the pretrained model. Could be either a huggingface model id or a local path. Default: 'stabilityai/TripoSR'" ) parser.add_argument( "chunk-size", default=8192, type=int, help="Evaluation chunk size for surface extraction and rendering. Smaller chunk size reduces VRAM usage but increases computation time. 0 for no chunking. Default: 8192" ) parser.add_argument( "mc-resolution", default=512, type=int, help="Marching cubes grid resolution. Default: 256" ) parser.add_argument( "output-dir", default="output", type=str, help="Output directory. Default: 'output'" ) args = parser.parse_args() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if args.device == "cuda": device = torch.device("cuda") else: device = torch.device("cpu") model = TSR(args.pretrained_model_name_or_path, device=device) model.eval() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if args.chunk_size > 0: chunk_size = args.chunk_size else: chunk_size = 0 if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if args.mc_resolution > 0: mc_resolution = args.mc_resolution else: mc_resolution = 256 if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if not os.path.exists(args.output_dir): os.mkdir(args.output_dir) if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() for image_path in args.image: if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() image = Image.open(image_path) if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch.cuda.is_available(): print(torch.cuda.device_count(), 'cuda.device_count()') # Should print the number of GPUs print(torch.cuda.get_device_name(0), 'cuda.get_device_name(0)') torch.cuda.synchronize() if torch

内容来源: VAST-AI-Research/TripoSR