心得:此代码可以很好地体现残差网络的构建

The complexity and accuracy of the neural network model

img1

Dependencies:

  Anaconda3-5.2.0-Windows-x86_64.exe
  cuda_10.0.130_411.31_win10.exe
  cudnn-10.0-windows10-x64-v7.4.2.24.zip
  h5py-2.8.0rc1-cp36-cp36m-win_amd64.whl
  numpy-1.16.4-cp36-cp36m-win_amd64.whl
  tensorflow_gpu-1.13.1-cp36-cp36m-win_amd64.whl
  torch-1.1.0-cp36-cp36m-win_amd64.whl
  torchvision-0.3.0-cp36-cp36m-win_amd64.whl

Visualization Results

  • resnet18 训练结果 1 img1
  • resnet101 训练结果 2 img1

Public Datasets:

  • cifar100

Experience:

Traceback (most recent call last):
  File "resnet18_train.py", line 89, in <module>
    main()
  File "resnet18_train.py", line 53, in main
    logits = model(x)
  File "D:\installpackage\ana\envs\tf361\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 891, in __call__
    outputs = self.call(cast_inputs, *args, **kwargs)
  File "C:\Users\33203\Desktop\lesson43\resnet.py", line 72, in call
    x = self.stem(inputs)
  File "D:\installpackage\ana\envs\tf361\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 891, in __call__
    outputs = self.call(cast_inputs, *args, **kwargs)
  File "D:\installpackage\ana\envs\tf361\lib\site-packages\tensorflow_core\python\keras\engine\sequential.py", line 270, in call
    outputs = layer(inputs, **kwargs)
  File "D:\installpackage\ana\envs\tf361\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 891, in __call__
    outputs = self.call(cast_inputs, *args, **kwargs)
  File "D:\installpackage\ana\envs\tf361\lib\site-packages\tensorflow_core\python\keras\layers\convolutional.py", line 197, in call
    outputs = self._convolution_op(inputs, self.kernel)
  File "D:\installpackage\ana\envs\tf361\lib\site-packages\tensorflow_core\python\ops\nn_ops.py", line 1134, in __call__
    return self.conv_op(inp, filter)
  File "D:\installpackage\ana\envs\tf361\lib\site-packages\tensorflow_core\python\ops\nn_ops.py", line 639, in __call__
    return self.call(inp, filter)
  File "D:\installpackage\ana\envs\tf361\lib\site-packages\tensorflow_core\python\ops\nn_ops.py", line 238, in __call__
    name=self.name)
  File "D:\installpackage\ana\envs\tf361\lib\site-packages\tensorflow_core\python\ops\nn_ops.py", line 2010, in conv2d
    name=name)
  File "D:\installpackage\ana\envs\tf361\lib\site-packages\tensorflow_core\python\ops\gen_nn_ops.py", line 1031, in conv2d
    data_format=data_format, dilations=dilations, name=name, ctx=_ctx)
  File "D:\installpackage\ana\envs\tf361\lib\site-packages\tensorflow_core\python\ops\gen_nn_ops.py", line 1130, in conv2d_eager_fallback
    ctx=_ctx, name=name)
  File "D:\installpackage\ana\envs\tf361\lib\site-packages\tensorflow_core\python\eager\execute.py", line 67, in quick_execute
    six.raise_from(core._status_to_exception(e.code, message), None)
  File "<string>", line 3, in raise_from
tensorflow.python.framework.errors_impl.UnknownError: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above. [Op:Conv2D]

出现上面的错误

      os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'**-----------------------------------(本代码按此方法解决)
       
      or
      
      physical_devices = tf.config.experimental.list_physical_devices('GPU')
      if len(physical_devices) > 0:
      tf.config.experimental.set_memory_growth(physical_devices[0], True)

tensorflow-gpu版本代码出现numpy错误

  • 其中一种解决方法:pip install --upgrade numpy

References:

  • 深度学习与TensorFlow 2入门实战(完整版)---龙曲良