更改已训练和保存的神经网络Keras

时间:2019-11-16 19:34:58

标签: python tensorflow keras shapes

我正在关注有关手势识别(https://www.youtube.com/watch?v=Y6oLbRKwmPk&t=39s)的教程 ,使用python,TensorFlow和Keras。 遗憾的是,该模型只是从JSON加载而来,并且也未提供训练图像。 由于该教程已有2年的历史,因此我不得不更改一些可以使用的导入文件。

这是错误:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".\HandDetector.py", line 54, in <module>
    create_file=True,epoch_save = 1)
  File "C:\Users\simon\Dev\opencsv\tensor\projekt\zu heftig\Hand Gesture Detection\Python Scripts And Model\HandGestureModel\NetLoader.py", line 42, in __init__
    self.load_model() #load model
  File "C:\Users\simon\Dev\opencsv\tensor\projekt\zu heftig\Hand Gesture Detection\Python Scripts And Model\HandGestureModel\NetLoader.py", line 70, in load_model
    self.model = model_from_json(loaded_model_json)
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\saving.py", line 492, in model_from_json
    return deserialize(config, custom_objects=custom_objects)
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\layers\__init__.py", line 55, in deserialize
    printable_module_name='layer')
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\utils\generic_utils.py", line 145, in deserialize_keras_object
    list(custom_objects.items())))
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\sequential.py", line 301, in from_config
    model.add(layer)
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\sequential.py", line 181, in add
    output_tensor = layer(self.outputs[0])
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\engine\base_layer.py", line 457, in __call__
    output = self.call(inputs, **kwargs)
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\layers\convolutional.py", line 171, in call
    dilation_rate=self.dilation_rate)
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 3650, in conv2d
    data_format=tf_data_format)
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\nn_ops.py", line 754, in convolution
    return op(input, filter)
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\nn_ops.py", line 838, in __call__
    return self.conv_op(inp, filter)
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\nn_ops.py", line 502, in __call__
    return self.call(inp, filter)
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\nn_ops.py", line 190, in __call__
    name=self.name)
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\ops\gen_nn_ops.py", line 725, in conv2d
    data_format=data_format, dilations=dilations, name=name)
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
    op_def=op_def)
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 3162, in create_op
    compute_device=compute_device)
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 3208, in _create_op_helper
    set_shapes_for_outputs(op)
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 2427, in set_shapes_for_outputs
    return _set_shapes_for_outputs(op)
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 2400, in _set_shapes_for_outputs
    shapes = shape_func(op)
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 2330, in call_with_requiring
    return call_cpp_shape_fn(op, require_shape_fn=True)
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 627, in call_cpp_shape_fn
    require_shape_fn)
  File "C:\Users\simon\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\framework\common_shapes.py", line 691, in _call_cpp_shape_fn_impl
    raise ValueError(err.message)
ValueError: Negative dimension size caused by subtracting 5 from 2 for 'conv3_1/convolution' (op: 'Conv2D') with input shapes: [1,9,2,20], [5,5,20,40].

还有更多这样的例外。 我正在使用Keras 2.2.4和Tensorflow 1.5.0。

我可以做些什么来解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

发生错误是因为我使用的是较新版本的keras 我需要添加

100000

在keras中的第一条Conv2D行中。 对不起,我的错。