本文整理匯總了Python中keras.json方法的典型用法代碼示例。如果您正苦於以下問題:Python keras.json方法的具體用法?Python keras.json怎麽用?Python keras.json使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類keras
的用法示例。
在下文中一共展示了keras.json方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: import_keras
# 需要導入模塊: import keras [as 別名]
# 或者: from keras import json [as 別名]
def import_keras(tries=10):
"""There is an issue when multiple processes import Keras simultaneously --
the file .keras/keras.json is sometimes not read correctly.
as a workaround, just try several times to import keras."""
for try_num in range(tries):
try:
stderr = sys.stderr
sys.stderr = open(os.devnull, 'w')
import keras
sys.stderr = stderr
return
except ValueError:
logging.warning("Unable to import keras. Trying again: {0:d}".format(try_num))
from time import sleep
sleep(0.1)
logging.error("Failed to import keras!")
示例2: feature_to_image
# 需要導入模塊: import keras [as 別名]
# 或者: from keras import json [as 別名]
def feature_to_image(features, height=28, width=28, channels=1, backend=K):
'''
Reshape a flattened image to the input format for convolutions.
Can be used either as a Keras operation using the default backend or
with numpy by using the argument backend=np
Conforms to the image data format setting defined in ~/.keras/keras.json
'''
if K.image_data_format() == "channels_first":
return backend.reshape(features, (-1, channels, height, width))
else:
return backend.reshape(features, (-1, height, width, channels))