0

I tried to run auto-keras in a demo, but it failed, the code as shown below:

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:

```
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)
```

From the log, I think the fit() function in class ImageClassifier got something wrong. Its init function in ImageClassifier didn't run well.

Someone may encounter this problem and solve it. If could, please share it.

Thanks in Advances.

soerface
  • 6,417
  • 6
  • 29
  • 50
Johnny
  • 1,112
  • 1
  • 13
  • 21

2 Answers2

1

You should run the code with Python 3.6. Using super() without arguments for class inheritance gives your error when running in Python 2.7:

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)

Returns:

TypeError: super() takes at least 1 argument (0 given)

See also the auto-keras website:

Installation The installation of Auto-Keras is the same as other python packages. Notably, currently we only support Python 3.6.

sdcbr
  • 7,021
  • 3
  • 27
  • 44
  • But there is an another error while using Python 3.6.6, when I called `clf.fit(x_train, y_train)` function that the error massage is shown `axes don't match array`. Look at Traceback, https://github.com/jhfjhfj1/autokeras/issues/38 – Johnny Aug 05 '18 at 10:14
  • That's a different issue. – sdcbr Aug 05 '18 at 10:45
  • The above error message `axes don't match array` means I have to reshape it with code `x_train = x_train.reshape(x_train.shape + (1,))`. But now it's running okay. Thanks again. – Johnny Aug 05 '18 at 11:52
  • 1
    Nice to hear that! – sdcbr Aug 05 '18 at 12:50
0

This is what I wrote and worked fine on 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)
skrao
  • 1
  • 1