Exception: Data must be 1-dimensional appears when trying to make a submission I am doing image classification, and until now I have built my network and evaluated it. The only thing that remains to do is to do the submission, so I have a blind test set which contains images with no labels, and using the model I have created, I have to make predictions on this blind test set.

I have 4 classes: HAZE, RAINY, SUNNY, SNOWY. My code is the following:

blind_testSet = '/content/drive/My Drive/Colab Notebooks/submission'

test_datagen_blind = ImageDataGenerator(
    featurewise_center=True,
    featurewise_std_normalization=True,
    rescale = 1. / 255
   )


test_generator_blind = test_datagen.flow_from_directory(
    directory=blind_testSet,
    target_size=(256, 256),
    color_mode="rgb",
    batch_size=batch_size,
    class_mode="categorical",
    shuffle=False
)

preds =transfer_model.predict_generator(test_generator_blind,verbose=1,steps=val_steps)


import pandas as pd
import numpy as np

predicted_class_indices=np.argmax(preds,axis=1)
labels = (train_generator.class_indices)
labels = dict((v,k) for k,v in labels.items())
print(labels)
predictions = [labels[k] for k in predicted_class_indices]
filenames=test_generator_blind.filenames
results=pd.DataFrame({"image ID":filenames,
                  "Predictions":preds})
results.to_csv("submission.csv",index=False)


the problem is that I get the error:

    Exception                                 Traceback (most recent call last)
&lt;ipython-input-22-37b4cd72c225&gt; in &lt;module&gt;()
      9 filenames=test_generator_blind.filenames
     10 results=pd.DataFrame({"image ID":filenames,
---&gt; 11                       "Predictions":preds})
     12 results.to_csv("submission.csv",index=False)

4 frames
/usr/local/lib/python3.6/dist-packages/pandas/core/internals/construction.py in 
sanitize_array(data, index, dtype, copy, raise_cast_failure)
    727     elif subarr.ndim &gt; 1:
    728         if isinstance(data, np.ndarray):
--&gt; 729             raise Exception("Data must be 1-dimensional")
    730         else:
    731             subarr = com.asarray_tuplesafe(data, dtype=dtype)

Exception: Data must be 1-dimensional


Can someone help me? Thanks.

[EDIT]I have also tried to to :

    preds =transfer_model.predict_generator(test_generator_blind,verbose=1,steps=val_steps).reshape(-1,1)


but it does not work and I get the same error.
Python tells you that the data you give for the column "predictions" is not 1-dimensional (i.e. it's not a flat list). And indeed preds is not a 1-dimensional array, what you want to give is the corresponding labels that you collected in predictions.

So Instead of this: 

results=pd.DataFrame({"image ID":filenames,
                  "Predictions":preds})


you probably want:

results=pd.DataFrame({"image ID":filenames,
                  "Predictions":predictions})