r/computervision • • 1h ago

Help: Theory CNN Generalisability Problems

Post image

Hi everyone!

So, I'm having a bit of difficulty with CNN generalisability.

My problem is that, given a camera image, we need to predict object pose e.g., rotation

A week ago, I was using a synthetic dataset. Using (unforseen) synthetic data, I get very low error. Using real data, however, it is a disaster. I though this might be a domain gap from sim-to-real.

So, I did some more data retrieval and now I have 2 distinct video feeds, so 2 real datasets. However, if I train on one, inference on the other is terrible. So, it is not sim-to-real, but a generalisation problem in general.

I do have a pre-processing, which I won't detail, but if you look at the image above what the CNN sees is quite similar to my scenario (just imagine they sre 64x64x3 images). Imagine really low errors on the left lamp (same training environment) and high on the right lamp (different camera/perspective etc).

Basically, one camera has a different FOV/lens/resolution, and the images might also have varying sizes (e.g. a lamp in one camera might be "chunkier" due to lens characteristics).

In teems of solutions, I have read that it is very healthy to augment your training data, especially for computer vision. This could be blur/brightness/contrast etc., that you can do natively in PyTorch.

Would this be a profitable direction? What are good steps to take to try to debug this? What are the standard practices in these situations? What are the features my CNN is learning that are so specific to one dataset?

I should mention, my CNN is almost certainly not the problem. I have another pipeline that uses a VAE, inspired from a paper that achieves very high accuracy not only for generalisability, but even for sim-to-real. This current architecture fails for my data.

Thanks for any response!

5 Upvotes

7 comments sorted by

4

u/FirstPrinciplesRobot 1h ago

Augmentation is worth doing, but I'd first work out which camera difference is actually hurting you. Since the two cameras differ in FOV, lens and resolution, the object ends up a different apparent size and shape in the crop, and blur or brightness jitter won't fix that. Try random scale, aspect and perspective augmentation, plus a bit of lens-distortion-style warping, so the net can't rely on one camera's geometry. Also check what happens when you resize: if one camera's crops are interpolated very differently, the net can latch onto that texture. For debugging, hold out one camera entirely, look at where the errors are worst (certain angles? certain distances?), and try Grad-CAM or occlusion tests to see whether it's looking at the object or at background cues that happen to differ per camera.

1

u/SnappySkillz 1h ago

Ah brilliant, thanks for your response! So, just to clarify, all of these transformations you recommended doing as pre-processing steps for the training data only? I.e., I should prioritise all pre-processing in one place than, e.g., in my synthetic data environment (Unreal Engine), where I can do similar distortions?

4

u/impatiens-capensis 1h ago

I'm a bit confused about what your training dataset is and what your test environment is.

Are you training on many (image,pose) pairs and hoping to generalize to any scene or is it... specifically for this lamp? You need to be more clear.

So, it is not sim-to-real, but a generalisation problem in general.

There's no reason to think a model trained on a single distribution will generalize to all others. Models learn exactly what they are told to learn, and often very little more than that. You need to find ways to make your training data look more diverse. You could even do augmentation with image-to-image generators to make your real images look synthetic or like other domains (i.e. make this image look like it was taken by a security camera, etc.) to add semantically structured noise.

1

u/SnappySkillz 1h ago

Hi! Ah, to clarify, I am training using image/pose pairs. I have a choice of datasets, either synthetic generators in both Blender and Unreal Engine (I have 100k samples) or from real videos (some thousands of frames of image/ground truth pairs).

I'm training in one domain and trying to bridge the gap with another. Ideally, I want the synthetic data to generalise, as then I have unlimited data which I can optimise and vary scenarios.

I agree that I could user gen AI to get other samples, but I've got so many images now, I suppose it makes sense to perform the transformations you mentioned on those?

Thanks for the response :)!

1

u/impatiens-capensis 42m ago

Are you training from scratch or fine-tuning/tuning a LoRA/etc. into an existing object pose detector?

1

u/Necessary-Meeting-28 1h ago

You can use camera intrinsics as a dense input to the CNN, using techniques such as Plücker coordinates. Training by augmenting camera intrinsics for your task also makes sense.

For pose cameras matter, especially for size and translation. If you train with one camera model will memorize that camera and will not generalize to others.

1

u/Dry-Snow5154 57m ago

I have 2 distinct video feeds

Please, tell me you don't just have 2 videos, train on one and expect it to generalize to another.

In my experience augmentations can deliver 92 -> 95% improvement, but never 60 -> 95%.

Synthetic data usually works when it looks like real data. If your doesn't it likely won't work.

The article you linked last time has a very simplistic use case. It is totally possible VAE learnt to differentiate the object by color alone, which won't work in any real scenario.