我尝试在演示中运行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)The error message as shown below:
```javascriptInitializing 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)从日志中,我认为ImageClassifier类中的fit()函数出错了。它在ImageClassifier中的初始化函数运行得并不好。
有些人可能会遇到这个问题并解决它。如果可以,请分享。
感谢预付款。
发布于 2018-08-03 20:08:44
您应该使用Python 3.6运行代码。在Python2.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)另请参阅自动keras website
安装Auto-Keras的安装与其他python包相同。值得注意的是,目前我们只支持Python3.6.
发布于 2018-08-19 09:52:17
这是我在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)https://stackoverflow.com/questions/51669992
复制相似问题