Code Monkey home page Code Monkey logo

Comments (6)

ashawkey avatar ashawkey commented on July 17, 2024 1

Hi,
If I understand correctly, you are trying to use the metrics for Trainer? It is an old piece of code I borrowed from my other projects, so it may be confusing to use.

An example of a metric class can be:

class ROCMeter:
    def __init__(self):
        self.truths = []
        self.preds = []

    def clear(self):
        self.truths = []
        self.preds = []

    def prepare_inputs(self, *inputs):
        outputs = []
        for i, inp in enumerate(inputs):
            if torch.is_tensor(inp):
                inp = inp.detach().cpu().numpy()
            outputs.append(inp)

        return outputs

    def update(self, preds, truths):
        # [B, ], [B, ]
        preds, truths = self.prepare_inputs(preds, truths)
        self.truths.append(truths)
        self.preds.append(preds)


    def measure(self):
        return roc_auc_score(np.concatenate(self.truths, 0), np.concatenate(self.preds, 0))

    def write(self, writer, global_step, prefix=""):
        writer.add_scalar(os.path.join(prefix, "roc"), self.measure(), global_step)

    def report(self):
        return f'ROC = {self.measure():.6f}'

and used like:

trainer = Trainer(..., metrics=[ROCMeter(),], ...)

I will add a PSNR metric recently.

from torch-ngp.

JoyHighmore avatar JoyHighmore commented on July 17, 2024

Thank you sooo much! I'll try to implement that. Moreover, can you explain in SDF why are you using the negative sign here? sdfs[self.num_samples // 2:] = -self.sdf_fn(points[self.num_samples // 2:])[:,None].astype(np.float32)

from torch-ngp.

ashawkey avatar ashawkey commented on July 17, 2024

@JoyHighmore I have added the PSNR metric, you can try now!
As for the sdf value, it is just a convention (inner is negative, outer is positive), without the negation it should also work since we extract surface at sdf == 0.

(Besides, I find that the PSNR for lego is still worse compared to the original implementation, and I'll try to figure it out. If you find any problem, welcome to report!)

from torch-ngp.

JoyHighmore avatar JoyHighmore commented on July 17, 2024

Sure, there is one more thing that I'd like to discuss. I've noticed that there are some code trying to calculate the sdf by igl.signed_distance. I've also implement both igl and pysdf. It is found that they had quite different results, which not only with the different values but also different indications for inside and outside categories. Do you have any thoughts? What's your consideration for the pysdf? Also, are you trying to have balanced positive and negative sdf since you are using self.num_samples // 2 in this equation?

Best,
Joy

from torch-ngp.

ashawkey avatar ashawkey commented on July 17, 2024

@JoyHighmore That's strange, the SDF value should be unique as long as the mesh is fixed. Inside/Outside doesn't really matter as the only difference is a negation.
In fact the pos/neg points are not balanced, I followed the original implementation to sample 1/8 random points, 3/8 surface points, and 4/8 perturbed surface points.

from torch-ngp.

ashawkey avatar ashawkey commented on July 17, 2024

closed for now.

from torch-ngp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.