DL4J中文文档/Keras模型导入/核心层
Keras 核心层
KerasFlatten
作为DL4J的Cnn或Rnn将Keras的Flatten层导入到前馈InputPreProcessor(输入预入理器)
KerasFlatten
public KerasFlatten(Map<String, Object> layerConfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/2fae0f84a417a6cd.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
isInputPreProcessor(是否为输入预处理器)
public boolean isInputPreProcessor()
![](https://img.haomeiwen.com/i14495907/5e157568250752f2.gif)
返回布尔值
public KerasFlatten(Map<String, Object> layerConfig, boolean enforceTrainingConfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/de530d521dc4a87b.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 参数 enforceTrainingConfig 是否强制执行与训练相关的配置选项
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
getInputPreprocessor
public InputPreProcessor getInputPreprocessor(InputType... inputType) throws InvalidKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/3bb1856514cd5426.gif)
为给定的输入类型获取适合的DL4J输入预处理器
- 参数 inputType 输入类型数组
- 返回 DL4J 输入预处理器
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 查看 org.deeplearning4j.nn.conf.InputPreProcessor
getOutputType
public InputType getOutputType(InputType... inputType) throws InvalidKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/b26ffc505557afb3.gif)
获取层输出类型
- 参数 inputType 输入类型数组
- 返回 按输入类型返回输出类型
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
KerasPermute
从Keras导入Permute层
KerasPermute
public KerasPermute(Map<String, Object> layerConfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/7fcb08f9bb72bdac.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
isInputPreProcessor(是否为输入预处理器)
public boolean isInputPreProcessor()
![](https://img.haomeiwen.com/i14495907/dd90ef3157c7a1ba.gif)
返回布尔值
public KerasPermute(Map<String, Object> layerConfig, boolean enforceTrainingConfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/cbfbe94354815cee.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 参数 enforceTrainingConfig 是否强制执行与训练相关的配置选项
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
getInputPreprocessor
public InputPreProcessor getInputPreprocessor(InputType... inputType) throws
InvalidKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/9eb759c94f920c2b.gif)
为给定的输入类型获取适合的DL4J输入预处理器
- 参数 inputType 输入类型数组
- 返回 DL4J 输入预处理器
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 查看 org.deeplearning4j.nn.conf.InputPreProcessor
getOutputType
public InputType getOutputType(InputType... inputType) throws InvalidKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/c5d7329eb08cde13.gif)
获取层输出类型
- 参数 inputType 输入类型数组
- 返回 按输入类型返回输出类型
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
KerasRepeatVector
导入Keras的RepeatVector层
KerasRepeatVector
public KerasRepeatVector(Map<String, Object> layerConfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/a045185848e4f84b.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
getOutputType
public InputType getOutputType(InputType... inputType) throws InvalidKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/b72490655958387f.gif)
获取层输出类型
- 参数 inputType 输入类型数组
- 返回 按输入类型返回输出类型
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
public KerasRepeatVector(Map<String, Object> layerConfig, boolean enforceTrainingConfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/4d24bb45ddf8125c.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 参数 enforceTrainingConfig 是否强制执行与训练相关的配置选项
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
getRepeatVectorLayer
public RepeatVector getRepeatVectorLayer()
![](https://img.haomeiwen.com/i14495907/232c59842c6ad925.gif)
获取 DL4J RepeatVector.
- 返回 RepeatVector
KerasMasking
导入Keras遮罩层
KerasMasking
public KerasMasking(Map<String, Object> layerConfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/30e409307add7dfe.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
getOutputType
public InputType getOutputType(InputType... inputType) throws InvalidKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/52e39a02bfe09740.gif)
获取层输出类型
- 参数 inputType 输入类型数组
- 返回 按输入类型返回输出类型
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
public KerasMasking(Map<String, Object> layerConfig, boolean enforceTrainingConfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/1a6c5ffb41043fe0.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 参数 enforceTrainingConfig 是否强制执行与训练相关的配置选项
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
getMaskingLayer
public MaskZeroLayer getMaskingLayer()
![](https://img.haomeiwen.com/i14495907/871718e965c39ab6.gif)
获取 DL4J MaskZeroLayer.
- 返回 MaskZeroLayer
KerasActivation
从Keras导入一个激活层
KerasActivation
public KerasActivation(Map<String, Object> layerConfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/4de1d6acab8e00a9.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
getOutputType
public InputType getOutputType(InputType... inputType) throws InvalidKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/62246e3c5be0e71c.gif)
获取层输出类型
- 参数 inputType 输入类型数组
- 返回 按输入类型返回输出类型
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
public KerasActivation(Map<String, Object> layerConfig, boolean enforceTrainingConfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/722bd607f14405e6.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 参数 enforceTrainingConfig 是否强制执行与训练相关的配置选项
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
getActivationLayer
public ActivationLayer getActivationLayer()
![](https://img.haomeiwen.com/i14495907/0de1c273441ce874.gif)
获取 DL4J ActivationLayer.
- 返回 ActivationLayer
KerasSpatialDropout
用于DL4J dropout层的Keras包装器,带有SpatialDropout,用于1D到3D.
KerasSpatialDropout
public KerasSpatialDropout(Integer kerasVersion) throws UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/799c8547787fcffe.gif)
从KerasLayer传递构造函数
- 参数 kerasVersion Keras主版本
- 抛出 UnsupportedKerasConfigurationException 不支持的 Keras 配置
getOutputType
public InputType getOutputType(InputType... inputType) throws InvalidKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/4001d9511c2a0e0a.gif)
获取层输出类型
- 参数 inputType 输入类型数组
- 返回 按输入类型返回输出类型
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
public KerasSpatialDropout(Map<String, Object> layerConfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/99f4b71543a1ea32.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
getSpatialDropoutLayer
public DropoutLayer getSpatialDropoutLayer()
![](https://img.haomeiwen.com/i14495907/bf9c51aa0942d0db.gif)
获取 带有空间 dropout的DL4J DropoutLayer
- 返回 DropoutLayer
KerasLambda
将DL4J SamedifFlambda包装到Keraslayer中
KerasLambda
public KerasLambda(Map<String, Object> layerConfig, SameDiffLayer sameDiffLayer)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/680768346062e720.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
getOutputType
public InputType getOutputType(InputType... inputType) throws InvalidKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/16e0c8e64672918c.gif)
获取层输出类型
- 参数 inputType 输入类型数组
- 返回 按输入类型返回输出类型
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
public KerasLambda(Map<String, Object> layerConfig, boolean enforceTrainingConfig,
SameDiffLayer sameDiffLayer)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/47eac77ffc50a5e0.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 参数 enforceTrainingConfig 是否强制执行与训练相关的配置选项
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
getSameDiffLayer
public SameDiffLayer getSameDiffLayer()
![](https://img.haomeiwen.com/i14495907/0bfa8a56e2917010.gif)
获取 DL4J SameDiffLayer.
- 返回 SameDiffLayer
KerasReshape
从Keras导入Reshape层
KerasReshape
public KerasReshape(Map<String, Object> layerConfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/b0d7d68c7ea34b51.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
isInputPreProcessor
public boolean isInputPreProcessor()
![](https://img.haomeiwen.com/i14495907/f5ecf5182418fe0d.gif)
public KerasReshape(Map<String, Object> layerConfig, boolean enforceTrainingConfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/2458b25ff38c874a.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 参数 enforceTrainingConfig 是否强制执行与训练相关的配置选项
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
getInputPreprocessor
public InputPreProcessor getInputPreprocessor(InputType... inputType) throws InvalidKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/74cf2054fe5c5d9c.gif)
为给定的输入类型获取适合的DL4J输入预处理器
- 参数 inputType 输入类型数组
- 返回 DL4J 输入预处理器
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 查看 org.deeplearning4j.nn.conf.InputPreProcessor
getOutputType
public InputType getOutputType(InputType... inputType) throws InvalidKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/da705327416c5128.gif)
获取层输出类型
- 参数 inputType 输入类型数组
- 返回 按输入类型返回输出类型
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
KerasMerge
导入一个Keras合并层作为DL4J的合并顶点
TODO: 处理改变合并行为的轴参数(需要更改dl4j?)
KerasMerge
public KerasMerge(Integer kerasVersion) throws UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/d3428755cc2bb600.gif)
从KerasLayer传递构造函数
- 参数 kerasVersion Keras主版本
- 抛出 UnsupportedKerasConfigurationException 不支持的 Keras 配置
getOutputType
public InputType getOutputType(InputType... inputType)
![](https://img.haomeiwen.com/i14495907/d8c04789dfb02d94.gif)
获取层输出类型
- 参数 inputType 输入类型数组
- 返回 按输入类型返回输出类型
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
public KerasMerge(Map<String, Object> layerConfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/56bfdfc141f0cb39.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
KerasDropout
从Keras导入Dropout层
KerasDropout
public KerasDropout(Map<String, Object> layerConfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/a536e0b11a3840c6.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
getOutputType
public InputType getOutputType(InputType... inputType) throws InvalidKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/54e577ce478a1f09.gif)
获取层输出类型
- 参数 inputType 输入类型数组
- 返回 按输入类型返回输出类型
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
public KerasDropout(Map<String, Object> layerConfig, boolean enforceTrainingConfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/ecc7400a3be54234.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 参数 enforceTrainingConfig 是否强制执行与训练相关的配置选项
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
getDropoutLayer
public DropoutLayer getDropoutLayer()
![](https://img.haomeiwen.com/i14495907/d3127c97017a7c7e.gif)
获取 DL4J DropoutLayer.
- 返回 DropoutLayer
KerasDense
从Keras导入一个密连层
KerasDense
public KerasDense(Integer kerasVersion) throws UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/60141d6f1510d132.gif)
从KerasLayer传递构造函数
- 参数 kerasVersion Keras主版本
- 抛出 UnsupportedKerasConfigurationException 不支持的 Keras 配置
getDenseLayer
public DenseLayer getDenseLayer()
![](https://img.haomeiwen.com/i14495907/941eda22271f0486.gif)
获取密连层
public KerasDense(Map<String, Object> layerConfig)
throws InvalidKerasConfigurationException, UnsupportedKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/56c63f3e01a58370.gif)
来自解析的keras层配置字典的构造函数。
- 参数 layerConfig 包含keras层配置的字典
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
- 抛出 UnsupportedKerasConfigurationException 不支持的无效的 Keras 配置
getOutputType
public InputType getOutputType(InputType... inputType) throws InvalidKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/0562943376a8250e.gif)
获取层输出类型
- 参数 inputType 输入类型数组
- 返回 按输入类型返回输出类型
- 抛出 InvalidKerasConfigurationException 无效的 Keras 配置
getNumParams
public int getNumParams()
![](https://img.haomeiwen.com/i14495907/7d84ac94e346fa47.gif)
返回层中可训练参数的数目。
setWeights
public void setWeights(Map<String, INDArray> weights) throws InvalidKerasConfigurationException
![](https://img.haomeiwen.com/i14495907/a9461e05453f7b87.gif)
设置层的权重
- 参数 weights 密连层权重