Open Green-li opened 6 years ago
change basestring to six.string_types (and remember to import six) if you are using py3.5
@kingfengji thanks!but another error occurs:
Traceback (most recent call last):
File "examples/demo_mnist.py", line 66, in <module>
X_train_enc = gc.fit_transform(X_train, y_train)
File "lib/gcforest/gcforest.py", line 31, in fit_transform
self.fg.fit_transform(X_train, y_train, X_test, y_test, train_config)
File "lib/gcforest/fgnet.py", line 54, in fit_transform
layer.fit_transform(train_config)
File "lib/gcforest/layers/fg_win_layer.py", line 92, in fit_transform
X_win = get_windows(X, self.win_x, self.win_y, self.stride_x, self.stride_y, self.pad_x, self.pad_y)
File "lib/gcforest/utils/win_utils.py", line 48, in get_windows
X_win = np.empty(( nc, n * nh * nw), dtype=np.float32)
TypeError: 'float' object cannot be interpreted as an integer
I change the code in line42,43 in win_utils.py,it doesn't work.
# from / to //
nh = (h - win_y) // stride_y + 1
nw = (w - win_x) // stride_x + 1
I got the same errors so:
Get Python 2.7.
Clone gcforest folder from "\lib\gcforest" to your Python 2.7 folder "\Lib\site-packages\gcforest".
Install all dependences less Keras(Tensorflow). Maybe if you need, download xgboost from https://www.lfd.uci.edu/~gohlke/pythonlibs/#xgboost in windows systems, install with pip install your-package_name.whl run from the directory of the file .whl downloaded.
In demo_mnist.py remove import of keras to get mnist.
Get MNIST from elsewhere, need be np.array of shape (samples,28,28) for X_train and X_test.
or
pip install python-mnist Download mnist dataset from http://yann.lecun.com/exdb/mnist/ (4 files in red links .gz) and put in some directory, I recomend in your Python 2.7 folder "\Lib\site-packages\mnist\MNIST" (need create folder MNIST).
Open your Python 2.7 folder "\Lib\site-packages\mnist\loader.py". Localize:
class MNIST(object):
def __init__(self, path=' ', mode='vanilla', return_type='lists', gz=False):"_
Change to, with "YOUR PYTHON 2.7 PATH" or set path to mnist dataset .gz files folder path
class MNIST(object):
def __init__(self, path='YOUR PYTHON 2.7 PATH\Lib\site-packages\mnist\MNIST', mode='vanilla', return_type='numpy', gz=True):"_
Create a new function inside class MNIST(Caution with "tabs" and "spaces" behind rows):
def load_data(self):
ims, labels = self.load(os.path.join(self.path, self.train_img_fname),
os.path.join(self.path, self.train_lbl_fname))
self.train_images = self.process_images(ims).reshape(60000,28,28)
self.train_labels = self.process_labels(labels)
ims, labels = self.load(os.path.join(self.path, self.test_img_fname),
os.path.join(self.path, self.test_lbl_fname))
self.test_images = self.process_images(ims).reshape(10000,28,28)
self.test_labels = self.process_labels(labels)
return self.train_images, self.train_labels, self.test_images, self.test_labels
Inside demo_mnist.py remove:
from keras.datasets import mnist
Insert:
from mnist import MNIST
Remove:
(X_train, y_train), (X_test, y_test) = mnist.load_data()
Insert:
mndata = MNIST()
X_train, y_train, X_test, y_test = mndata.load_data()
Run the demo from the example folder demo_mnist.py or demo_mnist.py --model demo_mnist-gc.json
Hello @Green-li , I'm not sure if you've found a solution yet. I was able to make a few modifications which resolved the issue in win_utils.py - I hope @kingfengji can confirm they don't mess anything up too much?
Specifically in the win_utils.py file, I made four modifications based on the observed error messages. Just below line 18, you may consider adding the following two lines:
k = int(k)
di = int(di)
Specifically, we're typecasting the k
and di
variables to ints.
Next, inside the get_windows()
method, locate the following two lines:
nh = (h - win_y) / stride_y + 1
nw = (w - win_x) / stride_x + 1
And add the following two lines below them:
nh = int(nh)
nw = int(nw)
Which are just more typecasts. This seemed to fix the issue for me, and I was able to use gcForest in both Cascade and Multigrained Scanning mode.
Big ups to @kingfengji . I hope my modifications aren't too troublesome though.
Please update this thread with the results of these modifications on your code. It'd be nice to know if they work for you too.
Regards, M.
Added @madarax64 , also modify fg_pool_layer.py, add
nh = int(nh)
nw = int(nw)
below
nh = (h - 1) / win_y + 1
nw = (w - 1) / win_x + 1
it worked @marooncn @madarax64. but another error occurs:
Traceback (most recent call last):
File "/examples/demo_mnist.py", line 77, in <module>
y_pred = gc.predict(X_test)
File "\lib\gcforest\gcforest.py", line 61, in predict
y_proba = self.predict_proba(X)
File "\lib\gcforest\gcforest.py", line 56, in predict_proba
X = self.fg.transform(X)
File "\lib\gcforest\fgnet.py", line 68, in transform
layer.transform()
File "\lib\gcforest\layers\fg_win_layer.py", line 130, in transform
y_proba = est.predict_proba(X_win)
AttributeError: 'NoneType' object has no attribute 'predict_proba'
it seems like that can't find the self.estimator1d[ti]
because I set the keep_model_in_mem false. how can i solve this? @kingfengji
it worked @marooncn @madarax64. but another error occurs:
Traceback (most recent call last): File "/examples/demo_mnist.py", line 77, in <module> y_pred = gc.predict(X_test) File "\lib\gcforest\gcforest.py", line 61, in predict y_proba = self.predict_proba(X) File "\lib\gcforest\gcforest.py", line 56, in predict_proba X = self.fg.transform(X) File "\lib\gcforest\fgnet.py", line 68, in transform layer.transform() File "\lib\gcforest\layers\fg_win_layer.py", line 130, in transform y_proba = est.predict_proba(X_win) AttributeError: 'NoneType' object has no attribute 'predict_proba'
it seems like that can't find the
self.estimator1d[ti]
because I set the keep_model_in_mem false. how can i solve this? @Tessic @kingfengji 我也遇到了同样的问题,请问您解决了吗? I meet the same question, how did you deal with this ? very thanks
Environment : python3.6, Centos 7.
code in
lib/gcforest/layers/fg_pool_layer.py
:while run using the config
examples/demo_mnist-gc.json
, it has an error:the basestring function is no longer used in python3.