Sitelet https://web.archive.org/web/20210117115455/https://github.com/modAL-python/modAL/issues/60
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can use modAl with keras multi_gpu_model?how should i do? #60

Open
awalker0215 opened this issue Nov 20, 2019 · 2 comments
Open

can use modAl with keras multi_gpu_model?how should i do? #60

awalker0215 opened this issue Nov 20, 2019 · 2 comments

Comments

@awalker0215
Copy link

@awalker0215 awalker0215 commented Nov 20, 2019

when I use modAl with keras multi_gpu_model,training occurred error like following:

Query no. 1
Traceback (most recent call last):
File "/home/es712/Documents/MingHan/pycode/test/ALtest.py", line 77, in
query_idx, query_instance = learner.query(X_pool, n_instances=100, verbose=0)
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/modAL/models/base.py", line 203, in query
query_result = self.query_strategy(self, *query_args, **query_kwargs)
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/modAL/uncertainty.py", line 152, in uncertainty_sampling
uncertainty = classifier_uncertainty(classifier, X, **uncertainty_measure_kwargs)
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/modAL/uncertainty.py", line 77, in classifier_uncertainty
classwise_uncertainty = classifier.predict_proba(X, **predict_proba_kwargs)
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/modAL/models/base.py", line 186, in predict_proba
return self.estimator.predict_proba(X, **predict_proba_kwargs)
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/tensorflow/python/keras/wrappers/scikit_learn.py", line 265, in predict_proba
probs = self.model.predict_proba(x, **kwargs)
AttributeError: 'Model' object has no attribute 'predict_proba'

@awalker0215 awalker0215 changed the title can use modAl with keras ?how should i do? can use modAl with keras multi_gpu_model?how should i do? Nov 20, 2019
@cosmic-cortex
Copy link
Member

@cosmic-cortex cosmic-cortex commented Nov 21, 2019

Hi!

As far as I understand the scikit-learn wrapper for Keras, it constructs the model using the build function you provide during the .fit() method, which is stored in the model attribute. From the error log you posted, I suspect the problem is that the model has not been constructed yet when you call learner.query(). Let me know if it helps!

@awalker0215
Copy link
Author

@awalker0215 awalker0215 commented Dec 4, 2019 •

Thank you for your answer.
I change keras library from tensorflow to origin,use example code from github and it can work.
finally code as following:
model = Sequential()
model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(28, 28, 1)))
model.add(Conv2D(64, (3, 3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(10, activation='softmax'))
try:
_model = keras.utils.multi_gpu_model(model,gpus=2)
print("Training using multiple GPUs..")
except ValueError:
_model = model
print("Training using single GPU or CPU..")
_model.compile(loss='categorical_crossentropy', optimizer='adadelta', metrics=['accuracy'])
However,I used resnet50 in keras as my learner,another error occurred
with tensorflow.device('/cpu:0'):
model = Sequential()
model.add(resnet50.ResNet50(include_top = False, pooling = 'avg', weights = None,input_tensor=Input(shape=(28, 28, 1))))
model.add(Dense(10, activation = 'softmax'))
adam = optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=None, decay=0.0, amsgrad=False)

and error is :

Training using multiple GPUs..
WARNING:tensorflow:From /home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.
Traceback (most recent call last):
File "/home/es712/Documents/MingHan/pycode/test/ALtest.py", line 92, in
verbose=1
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/modAL/models/learners.py", line 79, in init
X_training, y_training, bootstrap_init, **fit_kwargs)
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/modAL/models/base.py", line 63, in init
self._fit_to_known(bootstrap=bootstrap_init, **fit_kwargs)
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/modAL/models/base.py", line 106, in _fit_to_known
self.estimator.fit(self.X_training, self.y_training, **fit_kwargs)
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/keras/wrappers/scikit_learn.py", line 209, in fit
return super(KerasClassifier, self).fit(x, y, **kwargs)
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/keras/wrappers/scikit_learn.py", line 151, in fit
history = self.model.fit(x, y, **fit_args)
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/keras/engine/training.py", line 1213, in fit
self._make_train_function()
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/keras/engine/training.py", line 316, in _make_train_function
loss=self.total_loss)
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/keras/optimizers.py", line 543, in get_updates
p_t = p - lr_t * m_t / (K.sqrt(v_t) + self.epsilon)
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 815, in binary_op_wrapper
y = ops.convert_to_tensor(y, dtype=x.dtype.base_dtype, name="y")
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1039, in convert_to_tensor
return convert_to_tensor_v2(value, dtype, preferred_dtype, name)
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1097, in convert_to_tensor_v2
as_ref=False)
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1175, in internal_convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 304, in _constant_tensor_conversion_function
return constant(v, dtype=dtype, name=name)
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 245, in constant
allow_broadcast=True)
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/tensorflow/python/framework/constant_op.py", line 283, in _constant_impl
allow_broadcast=allow_broadcast))
File "/home/es712/pythonenvs/tensorflow1.13.1/tensorflow1.13.1/lib/python3.6/site-packages/tensorflow/python/framework/tensor_util.py", line 454, in make_tensor_proto
raise ValueError("None values not supported.")
ValueError: None values not supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.