本文整理汇总了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))