我尝试在演示中运行auto-keras,但失败,代码如下所示:
from keras.datasets import mnist
from autokeras.classifier import ImageClassifier
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = x_train.reshape(x_train.shape + (1,))
x_test = x_test.reshape(x_test.shape + (1,))
clf = ImageClassifier(verbose=True)
clf.fit(x_train, y_train, time_limit=12 * 60 * 60)
clf.final_fit(x_train, y_train, x_test, y_test, retrain=True)
y = clf.evaluate(x_test, y_test)
print(y)
```
错误消息如下所示:
```
Initializing search.
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-23-077a1b1d90e1> in <module>()
1 clf = ImageClassifier(verbose=True)
----> 2 clf.fit(x_train, y_train, time_limit=12 * 60 * 60)
3 clf.final_fit(x_train, y_train, x_test, y_test, retrain=True)
4 y = clf.evaluate(x_test, y_test)
5 print(y)
/Users/victor/virtualenvlist/mydlp2/lib/python2.7/site-packages/autokeras/classifier.pyc in fit(self, x_train, y_train, time_limit)
210 start_time = time.time()
211 while time.time() - start_time <= time_limit:
--> 212 run_searcher_once(x_train, y_train, x_test, y_test, self.path)
213 if len(self.load_searcher().history) >= constant.MAX_MODEL_NUM:
214 break
/Users/victor/virtualenvlist/mydlp2/lib/python2.7/site-packages/autokeras/classifier.pyc in run_searcher_once(x_train, y_train, x_test, y_test, path)
41 backend.set_session(sess)
42 searcher = pickle_from_file(os.path.join(path, 'searcher'))
---> 43 searcher.search(x_train, y_train, x_test, y_test)
44
45
/Users/victor/virtualenvlist/mydlp2/lib/python2.7/site-packages/autokeras/search.pyc in search(self, x_train, y_train, x_test, y_test)
156 def search(self, x_train, y_train, x_test, y_test):
157 if not self.history:
--> 158 self.init_search()
159
160 # Start the new process for training.
/Users/victor/virtualenvlist/mydlp2/lib/python2.7/site-packages/autokeras/search.pyc in init_search(self)
142 print('Initializing search.')
143 graph = DefaultClassifierGenerator(self.n_classes,
--> 144 self.input_shape).generate(self.default_model_len,
145 self.default_model_width)
146 model_id = self.model_count
/Users/victor/virtualenvlist/mydlp2/lib/python2.7/site-packages/autokeras/generator.pyc in __init__(self, n_classes, input_shape)
34 class DefaultClassifierGenerator(ClassifierGenerator):
35 def __init__(self, n_classes, input_shape):
---> 36 super().__init__(n_classes, input_shape)
37
38 def generate(self, model_len=constant.MODEL_LEN, model_width=constant.MODEL_WIDTH):
TypeError: super() takes at least 1 argument (0 given)
```
从日志中,我认为类fit()
中的ImageClassifier
函数出错了。 ImageClassifier中的init函数运行不正常。
有人可能会遇到此问题并解决。如果可以,请分享。
感谢前进。
答案 0 :(得分:1)
您应该使用Python 3.6运行代码。在Python 2.7中运行时,使用不带参数的super()
进行类继承会产生错误:
class Employee(object):
def __init__(self, wage):
self.wage = wage
class Developer(Employee):
# inherits from Employee
def __init__(self, wage):
super().__init__(wage)
test = Developer(1000)
返回:
TypeError: super() takes at least 1 argument (0 given)
另请参见自动喀拉拉语website:
安装 Auto-Keras的安装与其他python软件包相同。值得注意的是,目前我们仅支持Python 3.6。
答案 1 :(得分:0)
这是我在python 3.6上编写并正常工作的内容:
import autokeras as ak
import keras
from keras.datasets import mnist
(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train = x_train.reshape(x_train.shape + (1,))
x_test = x_test.reshape(x_test.shape + (1,))
clf = ak.ImageClassifier(verbose=True)
clf.fit(x_train, y_train)