plaidml: TypeError: Cannot cast scalar from dtype('O') to dtype('

I’ve been trying to get a LSTM based project up and running with PlainML.

I’m getting: TypeError: Cannot cast scalar from dtype('O') to dtype('<f4') according to the rule 'same_kind' error when running with PlaidML backend - this includes OpenCL / Metal / LLVM on all of: CPU / Intel Graphics 630 / AMD Radeon Pro 560X.

This error does not appear when simply running with Keras.

(env) $ python run_all.py
Using plaidml.keras.backend backend.
INFO:plaidml:Opening device "metal_amd_radeon_pro_560x.0 / opencl_amd_amd_radeon_pro_560x_compute_engine.0"
Compilation Time (s) : 0.00164794921875
Train on 2393 samples, validate on 423 samples
Traceback (most recent call last):
  File "run_all.py", line 121, in <module>
    results_config = run.run_configuration ([...])
  File "xxx/dev/run.py", line 107, in run_configuration
    model.fit(xs_norm[:,:,1:], ys_norm[:,1], batch_size=batch_size, epochs=epochs,
    validation_split=validation_split, callbacks=[esCallBack], shuffle=False)
  File "xxx/env/lib/python3.7/site-packages/keras/engine/training.py", line 1039, in fit
    validation_steps=validation_steps)
  File "xxx/env/lib/python3.7/site-packages/keras/engine/training_arrays.py", line 199, in fit_loop
    outs = f(ins_batch)
  File "xxx/env/lib/python3.7/site-packages/plaidml/keras/backend.py", line 165, in __call__
    val = variable(val, dtype=self._input_types[name]).var
  File "xxx/env/lib/python3.7/site-packages/plaidml/keras/backend.py", line 1669, in variable
    view.copy_from_ndarray(value)
  File "xxx/env/lib/python3.7/site-packages/plaidml/__init__.py", line 1174, in copy_from_ndarray
    np.copyto(dst, src)
TypeError: Cannot cast scalar from dtype('O') to dtype('<f4') according to the rule 'same_kind'

Here are examples of the values given to model.fit:

xs_norm[:,:,1:]: ... // type: <class 'numpy.ndarray'>
ys_norm[:,1]: ... // type: <class 'numpy.ndarray'>
batch_size: 32 // type: <class 'int'>
epochs: 1000 // type: <class 'int'>
validation_split: 0.15 // type: <class 'float'>
[esCallBack]: [<keras.callbacks.EarlyStopping object at 0x135838898>] // type: <class 'list'>

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 2
  • Comments: 18

Most upvoted comments

Also experiencing this bug. Works fine on Keras w/o PlaidML.

Relevant code snips follow below:

import plaidml.keras
plaidml.keras.install_backend()

from keras.models import Sequential
from keras.layers import Dense, Activation

[...]
def try_neural_classifier(X, y, X2, y2):
	model = Sequential()
	model.add(Dense(6,activation='relu',input_dim=X.shape[1]))
	model.add(Dense(1, activation='sigmoid'))
	model.compile(optimizer='rmsprop',
              loss='binary_crossentropy',
              metrics=['accuracy'])
	model.fit(X, y, epochs=110, batch_size=32, verbose=0)
	yP = model.predict_classes(X2, verbose=0)
	print_metrics(y2,yP, "NN")

Logs:

INFO:plaidml:Opening device “metal_intel®_iris™_plus_graphics_650.0” Traceback (most recent call last): File “<redacted>”, line 235, in <module> try_neural_classifier(X,y,X2,y2) File “<redacted>”, line 182, in try_neural_classifier model.fit(X, y, epochs=110, batch_size=32, verbose=0) File “/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/engine/training.py”, line 1039, in fit validation_steps=validation_steps) File “/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/keras/engine/training_arrays.py”, line 199, in fit_loop outs = f(ins_batch) File “/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plaidml/keras/backend.py”, line 164, in call val = variable(val, dtype=self._input_types[name]).var File “/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plaidml/keras/backend.py”, line 1736, in variable view.copy_from_ndarray(value) File “/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/plaidml/init.py”, line 1205, in copy_from_ndarray np.copyto(dst, src) File “<array_function internals>”, line 6, in copyto TypeError: Cannot cast scalar from dtype(‘O’) to dtype(‘<f4’) according to the rule ‘same_kind’