keras application 本地執行

2021-09-29 01:32:58 字數 2337 閱讀 2599

1、在匯入_obtain_input_shape時,

出現錯誤如下:

importerror: cannot import name '_obtain_input_shape'

2.在呼叫_obtain_input_shape時,

# determine proper input shape.

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)

出現錯誤如下:

typeerror: _obtain_input_shape() got an unexpected keyword argument 'include_top
原因是python版本》2.0以後會出現這種問題,函式已經改變了

將匯入語句修改如下

# determine proper input shape.

input_shape = _obtain_input_shape(input_shape,

default_size=224,

min_size=32,

data_format=k.image_data_format(),

require_flatten=include_top or weights)

重點:使用include_top代替require_flatten

3.使用本地的json檔案

import json

with open(『read_json.json』, 'r') as f:

temp = json.loads(f.read())

print(temp)

print(temp['rule'])

print(temp['rule']['namespace'])

4.如何讀取keras的.h5檔案

keras的模型是用hdf5儲存的,如果想要檢視模型,keras提供了get_weights的函式可以檢視:

for layer in model.layers:   

weights = layer.get_weights() # list of numpy array

而通過hdf5模組也可以讀取:hdf5的資料結構主要是file - group - dataset**,具體操作api可以看官方文件。weights的tensor儲存在dataset的value中,而每一集都會有attrs儲存各網路層的屬性:

import h5py

def print_keras_wegiths(weight_file_path):

f = h5py.file(weight_file_path) # 讀取weights h5檔案返回file類

try:

if len(f.attrs.items()):

print("{} contains: ".format(weight_file_path))

print("root attributes:")

for key, value in f.attrs.items():

print(" {}: {}".format(key, value)) # 輸出儲存在file類中的attrs資訊,一般是各層的名稱

for layer, g in f.items(): # 讀取各層的名稱以及包含層資訊的group類

print(" {}".format(layer))

print(" attributes:")

for key, value in g.attrs.items(): # 輸出儲存在group類中的attrs資訊,一般是各層的weights和bias及他們的名稱

print(" {}: {}".format(key, value))

print(" dataset:")

for name, d in g.items(): # 讀取各層儲存具體資訊的dataset類

print(" {}: {}".format(name, d.value.shape)) # 輸出儲存在dataset中的層名稱和權重,也可以列印dataset的attrs,但是keras中是空的

print(" {}: {}".format(name, d.value))

從github上轉殖的vue專案在本地執行

首先宣告,一般github上的作者都會說明具體的執行步驟,在這裡針對新手來提出乙個引導性的方案。1 安裝nodejs,具體步驟不多說。在電腦上找到 執行 輸入cmd 輸入node v 命令可以來檢視電腦上是否已裝 node 該命令代表電腦上node的版本。2 檢視npm版本 具體步驟同上,輸入的命令...

git操作 在本地倉庫新增運程倉庫,並同步遠端倉庫

在本地倉庫新增遠端倉庫,並同步遠端倉庫,步驟如下 一 在本地建立乙個目錄,在目錄在新增檔案,並初始化倉庫 mkdir testgit echo aaa testgitfile.txt sudo git init sudo git add sudo git commit m one test file...

運維(1)什麼是運維

運維,這裡指網際網路運維,通常屬於技術部門,與研發 測試 系統管理同為網際網路產品技術支撐的4大部門,這個劃分在國內和國外以及大小公司間都會多少有一些不同。乙個網際網路產品的生成一般經歷的過程是 產品經理 需求分析 研發部門開發 測試部門測試 運維部門部署發布以及長期的執行維護。對於初創公司,運維部...