mqwfrog / MHCCL

MHCCL: Masked Hierarchical Cluster-wise Contrastive Learning for Multivariate Time Series - a PyTorch Version (AAAI-2023)
30 stars 10 forks source link

Error: setting an array element with a sequence #4

Closed protti closed 10 months ago

protti commented 1 year ago

Hi, I'm trying to replicate your algorithm, but I've found a value error when I try to run the wisdm dataset:

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (3,) + inhomogeneous part.

This error is raised at:

augmentations.py, line 41, in permutation
    warp = np.concatenate(np.random.permutation(splits)).ravel()
  File "mtrand.pyx", line 4703, in numpy.random.mtrand.RandomState.permutation

Do you know how I can solve it?

mqwfrog commented 1 year ago

You can check the "max_segments" variable defined in the "permutation" method.

protti commented 1 year ago

The max_segments is equal to 5. I've noticed that the error changes each time. This is the line where the error happen: warp = np.concatenate(np.random.permutation(splits)).ravel()

I've tried to modify this line, with this piece of code:

shapes = [np.shape(arr) for arr in splits]
print(shapes) 
Assuming splits is a list of ndarrays with different shapes
grouped_splits = [
                [arr for arr in splits if arr.shape == shape]
                for shape in set(arr.shape for arr in splits)
            ]
permutation = np.concatenate([np.random.permutation(group[0]) for group in grouped_splits], axis=0)
 warp = permutation.ravel()

But now I receive this error:

File "PycharmProjects\MHCCL\dataloaderq\augmentations.py", line 53, in permutation
    ret[i] = pat[0,warp]
ValueError: could not broadcast input array from shape (240,) into shape (3,256)
mqwfrog commented 1 year ago

Hi~ As shown in the error report you received, the input format required by the model is (3, 256), which corresponds to (variables, length). You need to make sure that the format of x you feed into the model matches what the model expects. In my preprocessing file, the final x.shape is [samples, variables, length]. To troubleshoot the issue, I recommend outputting the intermediate results and examining what the value "240" in your error message refers to.