Skip to content

Missing Batch Dimension Error #3

@CaptainAlready

Description

@CaptainAlready

Hi! I might be wrong about this since I'm fairly new to the domain, so perhaps I've misunderstood something.

I'm trying to pass a dummy Sentinel-2 instance through the model. To do this, I'm using the provided code to import the model and then construct a sample compatible with Galileo input:

from single_file_galileo import Encoder as SingleFileEncoder
import torch
from pathlib import Path

DATA_FOLDER = Path("data")

sf_model = SingleFileEncoder.load_from_folder(
    DATA_FOLDER / "models/nano", device=torch.device("cpu")
)

from src.data.utils import S2_BANDS, construct_galileo_input
from src.masking import MaskedOutput

t, h, w = 2, 4, 4
s2 = torch.randn((t, h, w, len(S2_BANDS)))
masked_output = construct_galileo_input(s2=s2, normalize=True)

The problem I'm facing is related to tensor dimensions. For example, the shape of masked_output.space_time_x is torch.Size([2, 4, 4, 13]) -> [T, H, W, len(SPACE_TIME_BANDS)]. Similarly, masked_output.months.shape -> torch.Size([4]) . Essentially, the batch dimension B is missing?

This issue becomes apparent when passing masked_output through the model:

output = sf_model(
    masked_output.space_time_x,    
    masked_output.space_x,        
    masked_output.time_x,          
    masked_output.static_x,        
    masked_output.space_time_mask, 
    masked_output.space_mask,    
    masked_output.time_mask,       
    masked_output.static_mask,    
    masked_output.months,      
    patch_size=2            
)

This results in the following error:

File  /galileo/single_file_galileo.py:922, in Encoder.apply_linear_projection(self, s_t_x, sp_x, t_x, st_x, s_t_m, sp_m, t_m, st_m, patch_size)
    922     b, h, w, t, _ = s_t_x.shape
ValueError: not enough values to unpack (expected 5, got 4)

This makes sense given the missing batch dimension B.

I considered solving this issue by applying an unsqueeze operation to manually introduce a batch dimension, but I'm unsure if this approach is appropriate.

Again, it's entirely possible I've misunderstood something. Any guidance or clarification would be greatly appreciated. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions