Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用keras训练时报错 #8

Open
Totti0135 opened this issue Jul 8, 2020 · 14 comments
Open

使用keras训练时报错 #8

Totti0135 opened this issue Jul 8, 2020 · 14 comments

Comments

@Totti0135
Copy link

环境:
mac os 10.15.5
python 3.7.3
stagesepx 0.14.0
执行train_model.py 报一下错误

/Users/peter/PycharmProjects/stagesepx-demo/venv/bin/python /Users/peter/PycharmProjects/stagesepx-demo/test/train.py
2020-07-08 15:42:38.499 | DEBUG    | stagesepx.classifier.base:__init__:288 - no compress rate or target size received. set compress rate to 0.2
2020-07-08 15:42:38.499 | DEBUG    | stagesepx.classifier.base:__init__:294 - compress rate: 0.2
2020-07-08 15:42:38.499 | DEBUG    | stagesepx.classifier.base:__init__:295 - target size: None
2020-07-08 15:42:38.500 | DEBUG    | stagesepx.hook:__init__:13 - start initialing: CompressHook ...
2020-07-08 15:42:38.500 | DEBUG    | stagesepx.hook:__init__:80 - compress rate: 0.2
2020-07-08 15:42:38.500 | DEBUG    | stagesepx.hook:__init__:81 - target size: None
2020-07-08 15:42:38.500 | DEBUG    | stagesepx.hook:__init__:13 - start initialing: GreyHook ...
2020-07-08 15:42:38.500 | DEBUG    | stagesepx.classifier.base:add_hook:316 - add hook: CompressHook
2020-07-08 15:42:38.500 | DEBUG    | stagesepx.classifier.base:add_hook:316 - add hook: GreyHook
2020-07-08 15:42:38.500 | DEBUG    | stagesepx.classifier.keras:__init__:49 - score threshold: 0.0
2020-07-08 15:42:38.500 | DEBUG    | stagesepx.classifier.keras:__init__:50 - data size: (200, 200)
2020-07-08 15:42:38.500 | DEBUG    | stagesepx.classifier.keras:__init__:51 - nb train samples: 500
2020-07-08 15:42:38.500 | DEBUG    | stagesepx.classifier.keras:__init__:52 - nb validation samples: 500
2020-07-08 15:42:38.500 | DEBUG    | stagesepx.classifier.keras:__init__:53 - epochs: 10
2020-07-08 15:42:38.500 | DEBUG    | stagesepx.classifier.keras:__init__:54 - batch size: 32
2020-07-08 15:42:38.500 | DEBUG    | stagesepx.classifier.keras:train:138 - no model can be used. build a new one.
2020-07-08 15:42:38.500 | INFO     | stagesepx.classifier.keras:create_model:98 - creating keras sequential model
2020-07-08 15:42:38.510546: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-07-08 15:42:38.521419: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7f99fa87d8e0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-07-08 15:42:38.521446: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-07-08 15:42:38.609 | INFO     | stagesepx.classifier.keras:create_model:128 - model created
Found 112 images belonging to 7 classes.
Found 50 images belonging to 7 classes.
WARNING:tensorflow:From /Library/Python/3.7/site-packages/stagesepx/classifier/keras.py:170: Model.fit_generator (from tensorflow.python.keras.engine.training) is deprecated and will be removed in a future version.
Instructions for updating:
Please use Model.fit, which supports generators.
Epoch 1/10
2020-07-08 15:42:40.094593: W tensorflow/core/framework/op_kernel.cc:1753] OP_REQUIRES failed at sparse_xent_op.cc:90 : Invalid argument: Received a label value of 6 which is outside the valid range of [0, 6).  Label values: 6 1 6 0 6 6 6 1 0 6 4 6 6 6 0 1 6 2 0 6 0 6 6 5 3 3 4 6 6 1 0 0
Traceback (most recent call last):
  File "/Users/peter/PycharmProjects/stagesepx-demo/test/train.py", line 13, in <module>
    cl.train(data_home)
  File "/Library/Python/3.7/site-packages/stagesepx/classifier/keras.py", line 170, in train
    validation_steps=self.nb_validation_samples // self.batch_size,
  File "/Users/peter/PycharmProjects/stagesepx-demo/venv/lib/python3.7/site-packages/tensorflow/python/util/deprecation.py", line 324, in new_func
    return func(*args, **kwargs)
  File "/Users/peter/PycharmProjects/stagesepx-demo/venv/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", line 1479, in fit_generator
    initial_epoch=initial_epoch)
  File "/Users/peter/PycharmProjects/stagesepx-demo/venv/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", line 66, in _method_wrapper
    return method(self, *args, **kwargs)
  File "/Users/peter/PycharmProjects/stagesepx-demo/venv/lib/python3.7/site-packages/tensorflow/python/keras/engine/training.py", line 848, in fit
    tmp_logs = train_function(iterator)
  File "/Users/peter/PycharmProjects/stagesepx-demo/venv/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 580, in __call__
    result = self._call(*args, **kwds)
  File "/Users/peter/PycharmProjects/stagesepx-demo/venv/lib/python3.7/site-packages/tensorflow/python/eager/def_function.py", line 644, in _call
    return self._stateless_fn(*args, **kwds)
  File "/Users/peter/PycharmProjects/stagesepx-demo/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 2420, in __call__
    return graph_function._filtered_call(args, kwargs)  # pylint: disable=protected-access
  File "/Users/peter/PycharmProjects/stagesepx-demo/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 1665, in _filtered_call
    self.captured_inputs)
  File "/Users/peter/PycharmProjects/stagesepx-demo/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 1746, in _call_flat
    ctx, args, cancellation_manager=cancellation_manager))
  File "/Users/peter/PycharmProjects/stagesepx-demo/venv/lib/python3.7/site-packages/tensorflow/python/eager/function.py", line 598, in call
    ctx=ctx)
  File "/Users/peter/PycharmProjects/stagesepx-demo/venv/lib/python3.7/site-packages/tensorflow/python/eager/execute.py", line 60, in quick_execute
    inputs, attrs, num_outputs)
tensorflow.python.framework.errors_impl.InvalidArgumentError:  Received a label value of 6 which is outside the valid range of [0, 6).  Label values: 6 1 6 0 6 6 6 1 0 6 4 6 6 6 0 1 6 2 0 6 0 6 6 5 3 3 4 6 6 1 0 0
	 [[node sparse_categorical_crossentropy/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits (defined at Library/Python/3.7/site-packages/stagesepx/classifier/keras.py:170) ]] [Op:__inference_train_function_1008]

Function call stack:
train_function

@williamfzc
Copy link
Owner

williamfzc/stagesepx#112

@Totti0135
Copy link
Author

已解决,但是后面执行classify_with_model的以下语句时报ValueError错误
代码:r.draw(classify_result)
错误信息:

/Library/Python/3.7/site-packages/stagesepx/toolbox.py:254: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
  buffer = cv2.imencode(".png", frame)[1].tostring()
Traceback (most recent call last):
  File "/Users/anjuke/PycharmProjects/stagesepx-demo/test/classify_with_model.py", line 30, in <module>
    r.draw(classify_result)
  File "/Library/Python/3.7/site-packages/stagesepx/reporter.py", line 246, in draw
    for i in new_each
  File "<__array_function__ internals>", line 6, in hstack
  File "/Library/Python/3.7/site-packages/numpy/core/shape_base.py", line 346, in hstack
    return _nx.concatenate(arrs, 1)
  File "<__array_function__ internals>", line 6, in concatenate
ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 256 and the array at index 2 has size 160

@williamfzc
Copy link
Owner

ValueError: all the input array dimensions for the concatenation axis must match exactly

发下numpy版本?

@Totti0135
Copy link
Author

Totti0135 commented Jul 8, 2020

numpy: 1.19.0
使用主仓库mini.py是可以生成相关图表的

@williamfzc
Copy link
Owner

numpy: 1.19.0
使用主仓库mini.py是可以生成相关图表的

退到 0.18 可以解决问题吗?

@Totti0135
Copy link
Author

试了下1.17和1.18都不行

@williamfzc
Copy link
Owner

可能是个问题。视频方便发我一下吗?或者简单描述一下你们做了什么?

@Totti0135
Copy link
Author

可能是个问题。视频方便发我一下吗?或者简单描述一下你们做了什么?

已加QQ

@williamfzc
Copy link
Owner

可能是个问题。视频方便发我一下吗?或者简单描述一下你们做了什么?

已加QQ

没有收到哦

@Totti0135
Copy link
Author

Totti0135 commented Jul 10, 2020

可能是个问题。视频方便发我一下吗?或者简单描述一下你们做了什么?

已加QQ

没有收到哦

是这个qq吧?178894043

@oatsuper
Copy link

oatsuper commented Aug 6, 2020

请问下 最后怎么解决呢?

@oatsuper
Copy link

oatsuper commented Aug 6, 2020

usr/local/lib/python3.8/site-packages/stagesepx/toolbox.py:254: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
buffer = cv2.imencode(".png", frame)[1].tostring()
Traceback (most recent call last):
File "start.py", line 26, in
r.draw(classify_result)
File "/usr/local/lib/python3.8/site-packages/stagesepx/reporter.py", line 241, in draw
frame = np.hstack(
File "<array_function internals>", line 5, in hstack
File "/usr/local/lib/python3.8/site-packages/numpy/core/shape_base.py", line 346, in hstack
return _nx.concatenate(arrs, 1)
File "<array_function internals>", line 5, in concatenate
ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 320 and the array at index 1 has size 128

@williamfzc
Copy link
Owner

usr/local/lib/python3.8/site-packages/stagesepx/toolbox.py:254: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
buffer = cv2.imencode(".png", frame)[1].tostring()
Traceback (most recent call last):
File "start.py", line 26, in
r.draw(classify_result)
File "/usr/local/lib/python3.8/site-packages/stagesepx/reporter.py", line 241, in draw
frame = np.hstack(
File "<array_function internals>", line 5, in hstack
File "/usr/local/lib/python3.8/site-packages/numpy/core/shape_base.py", line 346, in hstack
return _nx.concatenate(arrs, 1)
File "<array_function internals>", line 5, in concatenate
ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 320 and the array at index 1 has size 128

是 0.14.1 吗?
试试 0.14.0 跟 0.13.1

@williamfzc
Copy link
Owner

理论上已修复,可以试试:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants