KeyError: 'classification_head_1/spatial_reduction_1/reduction_type'
See original GitHub issueAutoKeras version: master KerasTuner version: master TensorFlow version: 2.2.0
I am running a multi label image classifier based on the example code here: https://autokeras.com/tutorial/image_classification/
I was able to get the example code working with these dependency versions.
Now I am trying to modify the code to run on my own dataset. I have loaded in my own images and labels. I have set multi_label=True
since my dataset can have more than one label per image.
My process seems to be pretty standard. After loading in the data and labels, I transform them into numpy arrays, then use MultiLabelBinarizer
to pre-process, split into test and train sets, and run the image classiifer. Code is here:
data = np.array(data, dtype="float") / 255.0
labels = np.array(labels)
# binarize the labels using scikit-learn's special multi-label
# binarizer implementation
print("[INFO] class labels:")
mlb = MultiLabelBinarizer()
labels = mlb.fit_transform(labels)
# loop over each of the possible class labels and show them
for (i, label) in enumerate(mlb.classes_):
print("{}. {}".format(i + 1, label))
(x_train, x_test, y_train, y_test) = train_test_split(data, labels, test_size=0.2, random_state=42)
print(x_train.shape) # (60000, 28, 28)
print(y_train.shape) # (60000,)
print(y_train[:3]) # array([7, 2, 1], dtype=uint8)
Afterwards, code is straight from the example, except setting multi_label=True
:
# Initialize the image classifier.
clf = ak.ImageClassifier(max_trials=3, multi_label=True) # It tries 10 different models.
# Feed the image classifier with training data.
clf.fit(x_train, y_train, epochs=3)
# Predict with the best model.
predicted_y = clf.predict(x_test)
print(predicted_y)
# Evaluate the best model with testing data.
print(clf.evaluate(x_test, y_test))
The code runs fine for a few trials. Then, I get this error:
KeyError: 'classification_head_1/spatial_reduction_1/reduction_type'
[Warning] Invalid model 0/5
Here is the full stack trace:
Starting new trial
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 105, in build
model = self.hypermodel.build(hp)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 65, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/graph.py", line 235, in build
outputs = block.build(hp, inputs=temp_inputs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/engine/block.py", line 34, in _build_wrapper
return super()._build_wrapper(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 65, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/blocks/heads.py", line 82, in build
output_node = reduction.SpatialReduction().build(hp, output_node)
File "/usr/local/lib/python3.6/dist-packages/autokeras/engine/block.py", line 34, in _build_wrapper
return super()._build_wrapper(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 65, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/blocks/reduction.py", line 106, in build
default='global_avg')
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hyperparameters.py", line 691, in Choice
return self._retrieve(hp)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hyperparameters.py", line 619, in _retrieve
return self.values[hp.name]
KeyError: 'classification_head_1/spatial_reduction_1/reduction_type'
[Warning] Invalid model 0/5
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 105, in build
model = self.hypermodel.build(hp)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 65, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/graph.py", line 235, in build
outputs = block.build(hp, inputs=temp_inputs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/engine/block.py", line 34, in _build_wrapper
return super()._build_wrapper(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 65, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/blocks/heads.py", line 82, in build
output_node = reduction.SpatialReduction().build(hp, output_node)
File "/usr/local/lib/python3.6/dist-packages/autokeras/engine/block.py", line 34, in _build_wrapper
return super()._build_wrapper(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 65, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/blocks/reduction.py", line 106, in build
default='global_avg')
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hyperparameters.py", line 691, in Choice
return self._retrieve(hp)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hyperparameters.py", line 619, in _retrieve
return self.values[hp.name]
KeyError: 'classification_head_1/spatial_reduction_1/reduction_type'
[Warning] Invalid model 1/5
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 105, in build
model = self.hypermodel.build(hp)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 65, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/graph.py", line 235, in build
outputs = block.build(hp, inputs=temp_inputs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/engine/block.py", line 34, in _build_wrapper
return super()._build_wrapper(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 65, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/blocks/heads.py", line 82, in build
output_node = reduction.SpatialReduction().build(hp, output_node)
File "/usr/local/lib/python3.6/dist-packages/autokeras/engine/block.py", line 34, in _build_wrapper
return super()._build_wrapper(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 65, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/blocks/reduction.py", line 106, in build
default='global_avg')
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hyperparameters.py", line 691, in Choice
return self._retrieve(hp)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hyperparameters.py", line 619, in _retrieve
return self.values[hp.name]
KeyError: 'classification_head_1/spatial_reduction_1/reduction_type'
[Warning] Invalid model 2/5
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 105, in build
model = self.hypermodel.build(hp)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 65, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/graph.py", line 235, in build
outputs = block.build(hp, inputs=temp_inputs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/engine/block.py", line 34, in _build_wrapper
return super()._build_wrapper(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 65, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/blocks/heads.py", line 82, in build
output_node = reduction.SpatialReduction().build(hp, output_node)
File "/usr/local/lib/python3.6/dist-packages/autokeras/engine/block.py", line 34, in _build_wrapper
return super()._build_wrapper(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 65, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/blocks/reduction.py", line 106, in build
default='global_avg')
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hyperparameters.py", line 691, in Choice
return self._retrieve(hp)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hyperparameters.py", line 619, in _retrieve
return self.values[hp.name]
KeyError: 'classification_head_1/spatial_reduction_1/reduction_type'
[Warning] Invalid model 3/5
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 105, in build
model = self.hypermodel.build(hp)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 65, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/graph.py", line 235, in build
outputs = block.build(hp, inputs=temp_inputs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/engine/block.py", line 34, in _build_wrapper
return super()._build_wrapper(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 65, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/blocks/heads.py", line 82, in build
output_node = reduction.SpatialReduction().build(hp, output_node)
File "/usr/local/lib/python3.6/dist-packages/autokeras/engine/block.py", line 34, in _build_wrapper
return super()._build_wrapper(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 65, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/blocks/reduction.py", line 106, in build
default='global_avg')
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hyperparameters.py", line 691, in Choice
return self._retrieve(hp)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hyperparameters.py", line 619, in _retrieve
return self.values[hp.name]
KeyError: 'classification_head_1/spatial_reduction_1/reduction_type'
[Warning] Invalid model 4/5
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 105, in build
model = self.hypermodel.build(hp)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 65, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/graph.py", line 235, in build
outputs = block.build(hp, inputs=temp_inputs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/engine/block.py", line 34, in _build_wrapper
return super()._build_wrapper(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 65, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/blocks/heads.py", line 82, in build
output_node = reduction.SpatialReduction().build(hp, output_node)
File "/usr/local/lib/python3.6/dist-packages/autokeras/engine/block.py", line 34, in _build_wrapper
return super()._build_wrapper(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py", line 65, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/autokeras/blocks/reduction.py", line 106, in build
default='global_avg')
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hyperparameters.py", line 691, in Choice
return self._retrieve(hp)
File "/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hyperparameters.py", line 619, in _retrieve
return self.values[hp.name]
KeyError: 'classification_head_1/spatial_reduction_1/reduction_type'
[Warning] Invalid model 5/5
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py in build(self, hp)
104 with maybe_distribute(self.distribution_strategy):
--> 105 model = self.hypermodel.build(hp)
106 except:
17 frames
KeyError: 'classification_head_1/spatial_reduction_1/reduction_type'
During handling of the above exception, another exception occurred:
RuntimeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/kerastuner/engine/hypermodel.py in build(self, hp)
113 if i == self._max_fail_streak:
114 raise RuntimeError(
--> 115 'Too many failed attempts to build model.')
116 continue
117
RuntimeError: Too many failed attempts to build model.
How can I resolve this?
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (3 by maintainers)
Top GitHub Comments
@castrovictor Sure thing. I’m running using the following Dockerfile:
Running pip3 freeze inside the container gives the following:
and python version:
@dahlo would you mind posting your configuration? Installing the versions you mention I get this error:
ImportError: dlopen: cannot load any more object with static TLS
Contents of /mnt/sdd/vicastro/envs/ak4/lib/python3.8/site-packages/sklearn/__check_build: pycache setup.py _check_build.cpython-38-x86_64-linux-gnu.so init.py
It seems that scikit-learn has not been built correctly.