tensorflow: in train_validation_split raise ValueError( ValueError: `validation_split` is only supported for Tensors or NumPy arrays, found: (array([[[[0.24705882]
PyCharm Debian 10.3 Python 3.8.2 Cuda 10.2 cuDNN 7.6 Quadro K5200d drivers 440.82 Tensorflow 2.2.0-rc2
from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D import pickle
pickle_in = open(‘X.pickle’, ‘rb’) X = pickle.load(pickle_in) pickle_in = open(‘y.pickle’, ‘rb’) y = pickle.load(pickle_in) X = X/255.0
model = Sequential() model.add(Conv2D(256, (3, 3), input_shape=X.shape[1:])) model.add(Activation(‘relu’)) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Conv2D(256, (3, 3))) model.add(Activation(‘relu’)) model.add(MaxPooling2D(pool_size=(2, 2))) model.add(Flatten()) model.add(Dense(64)) model.add(Dense(1)) model.add(Activation(‘sigmoid’)) model.compile(loss=‘binary_crossentropy’, optimizer=‘adam’, metrics=[‘accuracy’]) model.fit(X, y, batch_size=64, epochs=3, validation_split=0.3)
2020-04-16 23:15:02.420846: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2020-04-16 23:15:02.438037: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties:
pciBusID: 0000:03:00.0 name: Quadro K5200 computeCapability: 3.5
coreClock: 0.771GHz coreCount: 12 deviceMemorySize: 7.94GiB deviceMemoryBandwidth: 179.05GiB/s
2020-04-16 23:15:02.438206: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library ‘libcudart.so.10.1’; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2020-04-16 23:15:02.439862: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2020-04-16 23:15:02.441466: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2020-04-16 23:15:02.441717: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2020-04-16 23:15:02.443456: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2020-04-16 23:15:02.444460: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2020-04-16 23:15:02.448122: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2020-04-16 23:15:02.448136: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1598] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices…
2020-04-16 23:15:02.448470: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-04-16 23:15:02.480562: I tensorflow/core/platform/profile_utils/cpu_utils.cc:102] CPU Frequency: 2394460000 Hz
2020-04-16 23:15:02.484972: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7fd3dc000b20 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-04-16 23:15:02.484998: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
2020-04-16 23:15:02.487117: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-04-16 23:15:02.487134: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]
Traceback (most recent call last):
File “/home/dominik/PycharmProjects/TensorFlow/dog_cat/model.py”, line 25, in <module>
model.fit(X, y, batch_size=64, epochs=3, validation_split=0.3)
File “/home/dominik/PycharmProjects/TensorFlow/venv/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py”, line 66, in _method_wrapper
return method(self, *args, **kwargs)
File “/home/dominik/PycharmProjects/TensorFlow/venv/lib/python3.8/site-packages/tensorflow/python/keras/engine/training.py”, line 732, in fit
data_adapter.train_validation_split((x, y, sample_weight),
File “/home/dominik/PycharmProjects/TensorFlow/venv/lib/python3.8/site-packages/tensorflow/python/keras/engine/data_adapter.py”, line 1314, in train_validation_split
raise ValueError(
ValueError: validation_split is only supported for Tensors or NumPy arrays, found: (array([[[[0.24705882],
[0.3372549 ],
[0.36078431],
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 23 (6 by maintainers)
I got the same error and resolved it by changing y into a numpy array
sure y=np.array(y) this is the only change you have to make.I have attatched the code below.Since I am getting some issue while uploading the folder .I have added a screenshot below
To add to that, after making “y” an array, I had to append the labels in a different way to avoid a different error. Here’s what I had:
I commented out the previous code that caused the post-numpy array-ization error.
This seemed to work on my custom dataset.
I tried everything proposed up here but nothing worked.
Until i changed ‘categorical_crossentropy’ to ‘sparse_categorical_crossentropy’, in the compiling function.
Hope this will help someone.
After changing to array you will face range issues while doing the split.