HHTseng / video-classification

Tutorial for video classification/ action recognition using 3D CNN/ CNN+RNN on UCF101
916 stars 216 forks source link

TypeError: Singleton array array(67, dtype=int64) cannot be considered a valid collection. #36

Closed abhiray92 closed 3 years ago

abhiray92 commented 3 years ago

Hi, has anyone got this error? I tried islolating the error, it turns out the error is probably in the train function. However, I cannot find a solution to this problem.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-15-373cd6a05bbe> in <module>
     15     # to compute accuracy
     16     y_pred = torch.max(output, 1)[1]  # y_pred != output
---> 17     step_score = accuracy_score(y.cpu().data.squeeze().numpy(), y_pred.cpu().data.squeeze().numpy())
     18     scores.append(step_score)         # computed on CPU
     19     loss.backward()

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\metrics\_classification.py in accuracy_score(y_true, y_pred, normalize, sample_weight)
    183 
    184     # Compute accuracy for each possible representation
--> 185     y_type, y_true, y_pred = _check_targets(y_true, y_pred)
    186     check_consistent_length(y_true, y_pred, sample_weight)
    187     if y_type.startswith('multilabel'):

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\metrics\_classification.py in _check_targets(y_true, y_pred)
     78     y_pred : array or indicator matrix
     79     """
---> 80     check_consistent_length(y_true, y_pred)
     81     type_true = type_of_target(y_true)
     82     type_pred = type_of_target(y_pred)

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py in check_consistent_length(*arrays)
    206     """
    207 
--> 208     lengths = [_num_samples(X) for X in arrays if X is not None]
    209     uniques = np.unique(lengths)
    210     if len(uniques) > 1:

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py in <listcomp>(.0)
    206     """
    207 
--> 208     lengths = [_num_samples(X) for X in arrays if X is not None]
    209     uniques = np.unique(lengths)
    210     if len(uniques) > 1:

C:\ProgramData\Anaconda3\lib\site-packages\sklearn\utils\validation.py in _num_samples(x)
    150         if len(x.shape) == 0:
    151             raise TypeError("Singleton array %r cannot be considered"
--> 152                             " a valid collection." % x)
    153         # Check that shape is returning an integer or default to len
    154         # Dask dataframes may not return numeric shape[0] value

TypeError: Singleton array array(67, dtype=int64) cannot be considered a valid collection.
abhiray92 commented 3 years ago

This issue has been closed

berna-ylmz commented 3 years ago

@abhiray92 I got the error.Could you share solution this problem?

abhiray92 commented 3 years ago

@Berna-lab Try to resize the batch size to a greater number.

TK-cosc commented 3 years ago

The batch_size is resized as 5, 10, 15, 45, 60, 100, ...... respectively, but this issue exists yet. @Berna-lab Did you solve the error?
@abhiray92 Could you share solution of the problem in detail?