work_with_stagesepx icon indicating copy to clipboard operation
work_with_stagesepx copied to clipboard

使用keras训练时报错

Open Totti0135 opened this issue 4 years ago • 14 comments

环境: 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

Totti0135 avatar Jul 08 '20 08:07 Totti0135

https://github.com/williamfzc/stagesepx/issues/112

williamfzc avatar Jul 08 '20 08:07 williamfzc

已解决,但是后面执行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

Totti0135 avatar Jul 08 '20 09:07 Totti0135

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

发下numpy版本?

williamfzc avatar Jul 08 '20 09:07 williamfzc

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

Totti0135 avatar Jul 08 '20 09:07 Totti0135

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

退到 0.18 可以解决问题吗?

williamfzc avatar Jul 08 '20 09:07 williamfzc

试了下1.17和1.18都不行

Totti0135 avatar Jul 08 '20 09:07 Totti0135

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

williamfzc avatar Jul 08 '20 09:07 williamfzc

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

已加QQ

Totti0135 avatar Jul 08 '20 09:07 Totti0135

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

已加QQ

没有收到哦

williamfzc avatar Jul 10 '20 08:07 williamfzc

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

已加QQ

没有收到哦

是这个qq吧?178894043

Totti0135 avatar Jul 10 '20 10:07 Totti0135

请问下 最后怎么解决呢?

oatsuper avatar Aug 06 '20 07:08 oatsuper

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

oatsuper avatar Aug 06 '20 07:08 oatsuper

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 avatar Aug 06 '20 08:08 williamfzc

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

  • 降级到 0.13.1
  • 升级到 0.14.2 并参考 https://github.com/williamfzc/stagesepx/issues/134

williamfzc avatar Aug 06 '20 15:08 williamfzc