AiuniAI / Unique3D

[NeurIPS 2024] Unique3D: High-Quality and Efficient 3D Mesh Generation from a Single Image
https://wukailu.github.io/Unique3D/
MIT License
3.07k stars 240 forks source link

RuntimeError #19

Closed hhchen-create closed 5 months ago

hhchen-create commented 5 months ago

Hi! Thanks for your great work!

I set up the environment as suggested but used RasterizeCudaContext rather than RasterizeGLContext.

Now, I encounter an error:

RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn.

This happens when the code runs into reconstruct_stage1 --> loss.backward().

So, could you please give some suggestions?

hhchen-create commented 5 months ago

The error mentioned above occurs when I do not use Gradio but directly call the function generate3dv2(). If I use Gradio, there is no problem.

fefespn commented 5 months ago

make sure you do all this before running calling the function:

if name == "main": import os import sys sys.path.append(os.curdir) if 'CUDA_VISIBLE_DEVICES' not in os.environ: os.environ['CUDA_VISIBLE_DEVICES'] = '0' os.environ['TRANSFORMERS_OFFLINE']='0' os.environ['DIFFUSERS_OFFLINE']='0' os.environ['HF_HUB_OFFLINE']='0' os.environ['GRADIO_ANALYTICS_ENABLED']='False' os.environ['HF_ENDPOINT']='https://hf-mirror.com'

import torch
torch.set_float32_matmul_precision('medium')
torch.backends.cuda.matmul.allow_tf32 = True

import gradio as gr import argparse

from app.gradio_3dgen import create_ui as create_3d_ui from app.all_models import model_zoo

import os import gradio as gr from PIL import Image from pytorch3d.structures import Meshes from app.utils import clean_up from app.custom_models.mvimg_prediction import run_mvprediction from app.custom_models.normal_prediction import predict_normals from scripts.refine_lr_to_sr import run_sr_fast from scripts.utils import save_glb_and_video from scripts.multiview_inference import geo_reconstruct

from rembg import remove from scripts.utils import session from app.utils import change_rgba_bg, rgba_to_rgb

model_zoo.init_models()

hhchen-create commented 5 months ago

hi, thanks for your quick and constructive response. I fixed this by setting torch.set_grad_enabled(True) in gradio_local.py. Thanks!