keras中遇到的錯誤


在運行其他開源keras項目時,遇到了一些問題:

1、在導入_obtain_input_shape時

from keras.applications.imagenet_utils import _obtain_input_shape

出現錯誤如下:

ImportError: cannot import name '_obtain_input_shape'

原因是在keras 2.2.2中,keras.applications.imagenet_utils模塊不再有_obtain_input_shape方法。解決方法:
將導入語句修改如下

from keras_applications.imagenet_utils import _obtain_input_shape
  • 重點:使用keras_applications代替keras.applications

2、在使用_obtain_input_shape方法時出現錯誤:

_obtain_input_shape() got an unexpected keyword argument 'include_top'

原因是我們的調用中使用了

input_shape = _obtain_input_shape(input_shape,
                                  default_size=224,
                                  min_size=32,
                                  data_format=K.image_data_format(),
                                  include_top=include_top or weights)

而在keras 2.2.2中函數 _obtain_input_shape() 的形式為:

def _obtain_input_shape(input_shape,
                        default_size,
                        min_size,
                        data_format,
                        require_flatten,
                        weights=None):

自然沒有include_top屬性。因此把調用中的include_top改為require_flatten即可


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM