附录Ⅴ. DLA SDK 辅助工具
1. DLA SDK辅助工具使用说明¶
工具 | 工具路径 | 工具作用 | 注意事项 |
---|---|---|---|
Offline模型信息查看工具 | SGS_IPU_SDK/DumpDebug/show_img_info.py | 查看Offline模型信息 | |
IPU Log性能分析工具 | SGS_IPU_SDK/Scripts/example/performance_timeline.py | 分析Offline模型性能 | 需配合SGS_IPU_SDK/cfg/IpuConfigS.ini 文件后重新转换原始模型到离线模型 |
IPU网络模型数据对比分析工具 | SGS_IPU_SDK/DumpDebug/auto_dump_debug.sh | 对比分析原模型/float/fix各阶段模型数据 | 需配合DumpDebugTool 工具使用 |
构造模型工具sgs_chalk | SGS_IPU_SDK/Scripts/calibrator_custom/sgs_chalk | 快速生成/Debug/float/fix各阶段模型 |
1.1 Offline模型信息查看工具¶
Offline模型信息查看工具:SGS_IPU_SDK/DumpDebug/show_img_info.py。
(1) 工具使用命令
python3 show_img_info.py \
-m deploy_fixed.sim_sgsimg.img \
--version
(2) 必选参数
-m
, --model
: 离线模型的路径
使用该参数将显示如下信息:
说明
-
Offline IMG Version
: 所用数据集生成该离线模型时用的SDK版本信息。 -
Offline Model Size
: 该离线模型的大小。 -
Offline Model Max Batch Numer
: 该离线模型的最大batch数。(compiler工具-b,--batch
参数) -
Offline Model Suggested Batch
: n_buf模型内可参考的batch数,实际使用时可设置为小于等于Max Batch Numer的任意batch数。(compilercompiler工具--batch_mode
参数) -
Offline Model Supported Batch
:one_buf模型内可使用的batch数,只能在这些batch数中进行选择。(compiler工具--batch_mode
参数) -
Offline Model Variable Buffer Size
: 该离线模型的Variable Buffer大小。 -
Offline_Model
:work_mode
: 该模型单核/双核模式信息(calibrator工具--work_mode
参数)-
Input
:name: 模型输入Tensor名称。
index: 模型输入Tensor索引。
dtype: 模型输入Tensor的数据类型,uint8/allint16
layouts: 模型输入Tensor的数据排布,NCHW/NHWC
shape: 模型输入Tensor的shape信息。
training_input_formats:网络训练时的图片格式信息(input_config
training_input_formats
参数)input_formats:网络模型在SigmaStar芯片上运行的图片输入格式(input_config
input_formats
参数)input_width_alignment:数据作为网络输入时Width方向对齐的数量(input_config
input_width_alignment
参数)input_height_alignment:数据作为网络输入时Height方向对齐的数量(input_config
input_height_alignment
参数)batch:该离线模型的batch数
batch_mode:模型的batch模式,n_buf/one_buf
-
Output
:name:模型输出Tensor名称。
index:模型输出Tensor索引
dtype:模型输出Tensor的数据类型,uint8/allint16
shape:模型输出Tensor的shape信息。
batch:该离线模型的batch数
batch_mode:模型的batch模式,n_buf/one_buf
(3) 可选参数
--version
: 生成离线模型所用的的SDK版本信息,即显示结果中SDK_Version_Info:
后打印的信息。
1.2 IPU Log性能分析工具¶
IPU Log性能分析工具位置:SGS_IPU_SDK/Scripts/example/performance_timeline.py
,将模型运行时生成的IPU Log 传入解析脚本, 会在当前目录下生成一个json格式文件,打开google浏览器,敲入chrome://tracing
,将生成的json文件拖入浏览器即可。
1.2.1 如何生成 IPU Log¶
打开SGS_IPU_SDK/cfg/IpuConfigS.ini
文件,设enable_performance_analyse=1
,重新转换原始模型到离线模型。
;ipu_configS.ini
[DEBUG_CONFIG]
enable_performance_analyse=1
运行offline模型,生成IPU Log。
prog_dla_dla_show_img_info \
-m deploy_fixed.sim_sgsimg.img \
--ipu_log logdir
-m
, --model
: 离线模型的路径 --ipu_log
: 生成ipu log的保存目录 1.2.2 如何使用IPU log生成json 文件¶
python3 ~/SGS_IPU_SDK/Scripts/example/performance_timeline.py \
-c0 log_ctrl0.bin\
-cc log_corectrl0.bin \
-f 900 \
-v 36X
参数解释如下:
-c0
, --core0
: core0 ipu log 文件的路径 (单核只需 core0 ipu log)
-cc
, --corectrl
: corectrl ipu log 文件路径 (可选)
-f
, --frequency
: ipu clk freq (默认为800)
-v
, --ipu_version
: ipu chip version (如:36X)
运行结束后,会在运行目录下生成log_ctrl0.json文件,将生成的json文件拖入浏览器chrome://tracing
即可显示每层的性能耗时占比,其中各指标术语解释如下:
指标术语
-
start:该层开始时间
-
wall duration:该层耗时
-
total_cycle:该层cycle数,与“wall duration”可以换算,wall duration = total_cycle/freq
-
conv_cycle_percent:该层conv运行时间占该层运行时间百分比
-
vector_cycle_percent:该层vector运行时间占该层运行时间百分比
-
dma_load_cycle_percent:该层dma load运行时间占该层运行时间百分比
-
dma_store_cycle_percent:该层dma store运行时间占该层运行时间百分比
-
conv/vertor/dma_load/dma_store指令可以并行执行,所以百分比相加不是100%
1.2.3 如何使用统计op耗时工具¶
python3 ~/SGS_IPU_SDK/Scripts/DumpDebug/get_op_time_cost.py \
-m fixed.sim \
--ipu_log_file log.json
参数解释如下:
-m
, 传入fixed.sim模型
ipu_log_file
,传入1.2.2节生成的json文件
运行结束后,屏幕上会按每类op耗时占比从高到底进行打印。
1.3 IPU网络模型数据对比分析工具¶
详情请参考手册 DumpDebug Tool章节
1.4 RPC_simulator工具¶
1.4.1 RPC_simulator工具介绍¶
RPC_simulator工具是IPU SDK基于TCP网络协议研发的远程仿真工具。通过在板端开启RPC服务,可以在PC仿真端一键获取离线模型板端推理结果;其与PC端simulator工具用法类似,客户使用起来简单高效,用于比较和验证offline模型在板端推理结果和PC端推理结果的一致性,提升模型移植效率。
1.4.2 RPC_simulator使用方法¶
(1) MI_SDK已提供sdk/verify/release_feature/source/dla/ipu_server 或 sdk/verify/mi_demo/source/dla/server 的app。
(2) 板端运行ipu_server开启RPC服务(PORT为设定的port号)
./prog_dla_server -p PORT
(3) PC端运行rpc_simulator.py
python3 SGS_IPU_SDK/Scripts/calibrator/rpc_simulator.py \
-i /path/to/input_data \
-m /path/to/offline.img \
-n /path/to/preprocess.py \
--host 板端ip地址 \
--port PORT
参数解释如下:
-i
: 推理图片
-m
: offline离线模型
-n
: 前处理文件
--host
: 板端ip地址
--port
: 设定端口号
(4) 运行结果保存在./log/output里,请和simulator.py执行offline模型的结果比较。
(5) 如果上述比较结果不一致,请提供原始模型给FAE分析。
注意
- RPC_simulator工具需要保证PC端和板端的网络连通,否则可能出现如下报错: 网络连通测试可以用
RuntimeError: std::future_error: Broken promise
nc
网络工具,操作方法如下:
板子上输入(PORT为设定的port号)PC上输入nc -l -p PORT
然后在PC终端输入字符,如果在板端能显示,说明可以传输,否则请检查PC端和板端的网络连接。nc 板端ip地址 PORT
- rpc_simulator.py设定的默认timeout时间为60秒,如果出现如下报错: 可能是文件太大,可在rpc_simulator.py增加配置timeout时间(单位:秒),如:
TimeoutError: Timeout for ipu_create_model
--timeout 100
- 板端内存空间有限,如遇到模型文件太大引起网络传输导致内存不足的情况,可按照如下方法操作:
拷贝模型文件到板端可以访问的路径,rpc_simulator.py增加设定模型在板端的路径配置--model_onboard_path 模型在板端的路径
--model_onboard_path
时,网络仅传输模型在板端路径的字符串,从而减小板端内存空间的使用。
1.5 构造模型工具sgs_chalk¶
1.5.1 sgs_chalk基本介绍¶
sgs_chalk是sigmastar自主研发的一款能够快速构建模型的工具,使用方法类似于开源深度学习框架pytorch和tensorflow,将sigmastar支持的算子封装成API,通过用户调用API构建脚本,生成最原始的debug.sim,并且通过设置相关参数,能够一步生成到float.sim和fixed.sim。下面会介绍具体的使用方法。
1.5.2 sgs_chalk使用方法¶
(1) 使用前首先需要在脚本开头添加以下语句
from calibrator_custom import sgs_chalk
构建tensor调用的接口为sgs_chalk.Tensor
,下面对传入参数进行介绍:
data
: 传入tensor的具体数据,需要是np.array格式
shape
: 传入tensor的shape
dtype
: 传入tensor的data的数据类型,不传的话默认是’ float32’,支持传入的数据类型为uint8
/int16
/float32
/int32
/int64
/complex64
name
: 传入tensor的name,如果不传的话会默认以prefix_数字命名,并且内部有检查机制,遇到重名tensor会进行重新命名
prefix
: 设置默认tensor命名的前缀
在sgs_chalk中,构建tensor主要分为以下两种,variable tensor会在构建operator时返回,一般无需用户创建
创建input tensor,调用sgs_chalk.Input接口
in0 = sgs_chalk.Input((1,28,28,1),name='input')
创建const tensor示例
weight1 = np.load("mnist_gen_weights/conv2d_4_kernel.npy")
weight1_tensor = sgs_chalk.Tensor(data=weight1,name='conv2d_4/kernel')
创建add
in0 = sgs_chalk.Input((28,512),name='input0')
in1 = sgs_chalk.Input((28,512),name='input1')
out0 = sgs_chalk.Add(in0,in1,name='output')
创建conv2d
in0 = sgs_chalk.Input((1,28,28,4),name='input0')
in1 = sgs_chalk.Input((8,3,3,4),name='input1')
out0 = sgs_chalk.Conv2d(in0,in1,name='output')
(4)构建model 构建model调用的接口为sgs_chalk.Model,下面对传入参数进行介绍: input_tensors: 传入输入tensor名称,集合为list形式 output_tensors: 传入输出tensor名称,集合为list形式
model = sgs_chalk.Model([in0],[out0])
(4)导出模型 导出模型应该在构建模型之后,调用接口如下:
model.save(model_path, input_config=None, convert_fixed=False, inputs=None)
-
仅保存debug模型:
会生成debug_test.sim模型model.save('test.sim')
-
会保存debug和float模型,需要配置input_config.ini
会生成Debug_test.sim和test.simmodel.save('test.sim',input_config='./input_config.ini')
-
保存fixed模型,convert_fixed=True,inputs=None:
会生成Debug_test.sim、test.sim和test_fixed.sim,这样的转换是基于默认量化导入的min/max转换的,因此有时候不能满足模型转换的精度需求。model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)
-
如果添加inputs参数,将会自动生成模型前处理文件,并按照inputs的内容即用户传入的图片等数据走sigmastar内部统计量化流程生成fixed.sim模型:
会读入inputs参数,根据input_config.ini的配置自动生成模型前处理脚本,量化生成fixed.sim模型model.save('test.sim', input_config='./input_config.ini', convert_fixed=True, inputs='0.jpg')
inputs参数有如下几种用法:
-
inputs=/path/to/img_dir 或 inputs=/path/to/img.jpg 如果input_config.ini中有模型输入的training_input_formats为RGB / BGR / GRAY,可以选用此用模式。
-
inputs=/path/to/npy_dir 或 inputs=/path/to/data.npy 如果input_config.ini中模型输入均为RAWDATA_S16_NHWC / RAWDATA_F32_NHWC / RAWDATA_COMPLEX64,可以选用此用模式。需要注意的是输入数据必须为numpy的npy格式
-
inputs=/path/to/img.txt input_config.ini中有多个输入时,可以选用此用模式
-
inputs='RAWDATA' 如果input_config.ini中所有模型输入均为RAWDATA_S16_NHWC / RAWDATA_F32_NHWC / RAWDATA_COMPLEX64,可以选用此用模式。‘RAWDATA’模式提前配置好模型输入的min/max,保存模型是会生成基于模型输入配置的min/max输入文件和前处理,并转换生成fixed模型。此模式仅被用来测试构造出的模型能否按照sigmastar内部统计的量化流程生成到fix模型。
1.5.3 sgs_chalk模块API¶
- Abs:
Computes the absolute value of a tensor.
Given a tensor of integer or floating-point values, this operation returns a tensor of the same type, where each element contains the absolute value of the corresponding element in the input.
Args:
x: A `Tensor`
Returns:
A `Tensor` of same shape and type as `x`.
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Abs(in0,name='output')
model = sgs_chalk.Model([in0],[out0])
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- Add:
Returns x + y element-wise.
Args:
x: A `Tensor`. Must be Variable Tensor.
y: A `Tensor` or `numpy.ndarray`. Must have the same type as `x`, can be Variable or Const Tensor.
Support inner most dimension broadcasting.
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as `x`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
in1 = sgs_chalk.Input((28,512),name='input1')
out0 = sgs_chalk.Add(in0,in1,name='output')
model = sgs_chalk.Model([in0,in1],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Add(in0,5.0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Alpha_Blending:
output = [alpha * input0 + (1 - alpha) * input1] ==> output = [alpha * (input0 - input1) + input1]
Args:
x1: A `Tensor`
x2: A `Tensor`
alpha: A `Tensor`
name: A name for the model output tensor (optional).
Returns:
A `Tensor`
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input1 = sgs_chalk.Input((1,1,36,2048), name='input0')
input2 = sgs_chalk.Input((1,1,36,2048), name='input1')
alpha = sgs_chalk.Input((1,1,36,2048), name='alpha')
out = sgs_chalk.Alpha_Blending(input1,input2,alpha, name='output')
model = sgs_chalk.Model([input1,input2,alpha], out)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)
- Argmax:
Returns the indices of the maximum values along an axis.
Args:
x: A `Tensor`. Must be Variable Tensor.
axis: int
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`. It has the same shape as `x.shape`
with the dimension along `axis` removed.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1, 80, 512),name='input0')
out0 = sgs_chalk.Argmax(in0, 1, name='output')
model.save('test.sim')
- Atan:
Args:
input: x `Tensor`. Must be Variable Tensor.
name: A name for the model output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as input.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input = sgs_chalk.Input((1,224,224,3),name='input')
out = sgs_chalk.Atan(input,name='output')
model = sgs_chalk.Model([input,], out)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)
- Atan2:
Element-wise arctangent of input0
and input1
with consideration of the quadrant. Returns a new tensor with the signed angles in radians between (-pi, pi)
Args:
input:0 A `Tensor`. Must be Variable Tensor.
input1: A `Tensor`. Must be Variable Tensor.
name: A name for the model Output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as input.
Examples:
case0
from calibrator_custom import sgs_chalk
input0 = sgs_chalk.Input((1, 22535), name='input0')
input1 = sgs_chalk.Input((1, 22535), name='input1')
out = sgs_chalk.Atan2(input0, input1, name='output')
model = sgs_chalk.Model([input0, input1], out)
model.save('atan2.sim', input_config='./input_config.ini', convert_fixed=True)
- Average_Pool_2D:
Performs the average pooling on the input. Each entry in output
is the mean of the corresponding size ksize
window in value
.
Args:
x: A 4-D `Tensor` of shape `[batch, height, width, channels]`
ksize: A list of `ints` that has length `1`, `2` or `4`. The size of
the window for each dimension of the input tensor.
strides: An int or list of `ints` that has length `1`, `2` or `4`. The
stride of the sliding window for each dimension of the input tensor.
padding: a tuple (paddingLeft, paddingRight, paddingTop, paddingBottom).
name: Optional name for the operation.
Returns:
The average pooled output tensor.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,28,28,4),name='input0')
out0 = sgs_chalk.Average_Pool_2D(in0,[2,2],name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,112,112,3),name='input0')
out0 = sgs_chalk.Average_Pool_2D(in0,[2,2],name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- Average_Pool_3D:
Performs the average pooling on the input. Each entry in output
is the mean of the corresponding size ksize
window in value
.
Args:
x: A 5D `Tensor` of shape `[batch, height, width, channels]`
ksize: A list of `ints` that has length `3`. The size of
the window for each dimension of the input tensor.
strides: An int or list of `ints` that has length `3`. The
stride of the sliding window for each dimension of the input tensor.
padding: a tuple (paddingI,paddingL,paddingT,paddingO,paddingR,paddingB).
name: Optional name for the operation.
Returns:
The average pooled output tensor.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,3,28,28,4),name='input0')
out0 = sgs_chalk.Average_Pool_3D(in0,[2,2,2],name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- BatchMatMul:
Multiplies matrix a
by matrix b
, producing a
* b
.
The inputs must be tensors of rank >= 2 where the inner 2 dimensions specify valid matrix multiplication arguments, and any further outer dimensions match.
Args:
x: input variable tensor and rank > 1.
y: input tensor with same type and rank as x,can be variable or const tensor.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,28,28,4),name='input0')
in1 = sgs_chalk.Input((1,28,28,4),name='input1')
out0 = sgs_chalk.BatchMatMul(in0,in1,name='output')
model = sgs_chalk.Model([in0,in1],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
input1 = np.ones((1,28,28,4), dtype=np.float32)
in0 = sgs_chalk.Input((1,28,512,4),name='input0')
out0 = sgs_chalk.BatchMatMul(in0,input1,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- BoxDecoder:
sigmastar postprocess BoxDecoder
Args:
unpacked_box: a list of tensors which are unpacked
Return:
a list of tensors decoded
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
box_num = 9
side_x = 19
side_y = 19
ppw = anchor.ones(3249)
px = anchor.index_div_linear(1,1,0,box_num ,side_x,side_y)
pph = anchor.ones(3249)
py = anchor.index_div_linear(1,1,0,side_x*box_num,side_y,1)
pw = anchor.ones(3249)
ph = anchor.ones(3249)
sx = anchor.ns(3249,1.0/19)
sy = anchor.ns(3249,1.0/19)
biases= [[9.5,9.5],[9.5,9.5],[9.5,9.5],[9.5,9.5],[9.5,9.5],[9.5,9.5],[9.5,9.5],[9.5,9.5],[9.5,9.5]]
sw = [x[0]/(2*19) for x in biases ]*(19*19)
sh = [x[1]/(2*19) for x in biases ]*(19*19)
config = {"shape" : [1,3249],
"tx_func" : (tflite.BuiltinOperator.BuiltinOperator().LOGISTIC,None),#None or 'x_scale'
"ty_func" : (tflite.BuiltinOperator.BuiltinOperator().LOGISTIC,None),#None or 'y_scale'
"tw_func" : (tflite.BuiltinOperator.BuiltinOperator().RESHAPE,None),#None or 'w_scale'
"th_func" : (tflite.BuiltinOperator.BuiltinOperator().RESHAPE,None),#None or 'h_scale'
"x_scale" : 0.1,
"y_scale" : 0.1,
"w_scale" : 1,
"h_scale" : 1,
"anchor_selector" : "constant",
"pw" : pw,
"ph" : ph,
"pw_func" : (None,None),
"ph_func" : (None,None),
"ppw" : ppw,
"px" : px,
"pph" : pph,
"py" : py,
"sx" : sx,
"sy" : sy,
"sw" : sw,
"sh" : sh
}
in0 = sgs_chalk.Input(model_config["input_shape"][0], name = model_config["input"][0])
unpack_out_tensors1 = []
for i in range(7):
unpack_out_tensors1.append("SGS_unpack1_"+str(i))
output_list = sgs_chalk.PostProcess_Unpack(in0,name=unpack_out_tensors1)
bosdecoder_output_list = sgs_chalk.BoxDecoder(config,output_list)
model = sgs_chalk.Model([in0],bosdecoder_output_list)
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- BoxDecoder2:
sigmastar postprocess BoxDecoder2
Args:
unpacked_box: a list of tensors which are unpacked
Return:
:return:a list of tensors decoded
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
box_num = 9
side_x = 19
side_y = 19
ppw = anchor.ones(3249)
px = anchor.index_div_linear(1,1,0,box_num ,side_x,side_y)
pph = anchor.ones(3249)
py = anchor.index_div_linear(1,1,0,side_x*box_num,side_y,1)
pw = anchor.ones(3249)
ph = anchor.ones(3249)
sx = anchor.ns(3249,1.0/19)
sy = anchor.ns(3249,1.0/19)
biases= [[9.5,9.5],[9.5,9.5],[9.5,9.5],[9.5,9.5],[9.5,9.5],[9.5,9.5],[9.5,9.5],[9.5,9.5],[9.5,9.5]]
sw = [x[0]/(2*19) for x in biases ]*(19*19)
sh = [x[1]/(2*19) for x in biases ]*(19*19)
config = {"shape" : [1,3249],
"tx_func" : (tflite.BuiltinOperator.BuiltinOperator().LOGISTIC,None),#None or 'x_scale'
"ty_func" : (tflite.BuiltinOperator.BuiltinOperator().LOGISTIC,None),#None or 'y_scale'
"tw_func" : (tflite.BuiltinOperator.BuiltinOperator().RESHAPE,None),#None or 'w_scale'
"th_func" : (tflite.BuiltinOperator.BuiltinOperator().RESHAPE,None),#None or 'h_scale'
"x_scale" : 0.1,
"y_scale" : 0.1,
"w_scale" : 1,
"h_scale" : 1,
"anchor_selector" : "constant",
"pw" : pw,
"ph" : ph,
"pw_func" : (None,None),
"ph_func" : (None,None),
"ppw" : ppw,
"px" : px,
"pph" : pph,
"py" : py,
"sx" : sx,
"sy" : sy,
"sw" : sw,
"sh" : sh
}
in0 = sgs_chalk.Input(model_config["input_shape"][0], name = model_config["input"][0])
unpack_out_tensors1 = []
for i in range(7):
unpack_out_tensors1.append("SGS_unpack1_"+str(i))
output_list = sgs_chalk.PostProcess_Unpack(in0,name=unpack_out_tensors1)
bosdecoder_output_list = sgs_chalk.BoxDecoder(config,output_list)
model = sgs_chalk.Model([in0],bosdecoder_output_list)
#model.save('test.sim')
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- Clip:
Clips tensor values to a specified min and max.
Given a tensor x
, this operation returns a tensor of the same type and shape as x
with its values clipped to min_value
and max_value
. Any values less than min_value
are set to min_value
. Any values greater than max_value
are set to max_value
.
Args:
x: A `Tensor`. Must be Variable Tensor.
min_value: A value.
max_value: A value.
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`. has the same shape as x
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input = sgs_chalk.Input((1,36,2048), name='input')
output = sgs_chalk.Clip(input,0,1, name='output')
model = sgs_chalk.Model([input,], output)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)
- Concatenation:
Concatenates the list of tensors values
along dimension axis
. If values[i].shape = [D0, D1, ... Daxis(i), ...Dn]
, the concatenated result has shape [D0, D1, ... Raxis, ...Dn] where Raxis = sum(Daxis(i)) That is, the data from the input tensors is joined along the axis
dimension. The number of dimensions of the input tensors must match, and all dimensions except axis
must be equal.
Args:
values: A list of `Tensor` objects or a single `Tensor`.
axis: 0-D `int32` `Tensor`. Dimension along which to concatenate. Must be
in the range `[-rank(values), rank(values))`. As in Python, indexing for
axis is 0-based. Positive axis in the rage of `[0, rank(values))` refers
to `axis`-th dimension. And negative axis refers to `axis +
rank(values)`-th dimension.
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512,1),name='input0')
in1 = sgs_chalk.Input((28,512,2),name='input1')
in2 = sgs_chalk.Input((28,512,3),name='input2')
x = [in0, in1, in2]
out0 = sgs_chalk.Concatenation(x,axis=2,name='output')
model = sgs_chalk.Model(x,out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,1,512),name='input0')
in1 = sgs_chalk.Input((28,2,512),name='input1')
in2 = sgs_chalk.Input((28,3,512),name='input2')
x = [in0, in1, in2]
out0 = sgs_chalk.Concatenation(x,axis=1,name='output')
model = sgs_chalk.Model(x,out0)
model.save('test.sim')
- CondGreat:
x0[i] > x1 ? x3:x2[i]
Args:
x0: `Tensor`. Must be Variable Tensor.
x1: A value.
x2: `Tensor`. Must be Variable Tensor, has same shape as x0.
x3: A value
name: A name for the model output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as input x0.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
from numpy import random as nr
input0 = sgs_chalk.Input((1,224,224,3),name='input0')
input1 = sgs_chalk.Input((1,224,224,3),name='input1')
out = sgs_chalk.CondGreat(input0,2.0,input1,1.0,name='output')
model = sgs_chalk.Model([input0,input1], out)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True,inputs='RAWDATA')
- CondLess:
x0[i] < x1 ? x3:x2[i]
Args:
x0: `Tensor`. Must be Variable Tensor.
x1: A value.
x2: `Tensor`. Must be Variable Tensor, has same shape as x0.
x3: A value
name: A name for the model output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as input x0.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
from numpy import random as nr
input0 = sgs_chalk.Input((1,224,224,3),name='input0')
input1 = sgs_chalk.Input((1,224,224,3),name='input1')
out = sgs_chalk.CondLess(input0,2.0,input1,1.0,name='output')
model = sgs_chalk.Model([input0,input1], out)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True,inputs='RAWDATA')
- Conv2d:
Conv2d
Args:
x : input tensor of shape(1, iH, iW,in_channels)
weight: filters of shape(out_channels, kH, kW, in_channels)
bias: optional bias tensor of shape(out_channels).Default:None
stride: the stride of the convolving kernel. Can be a single number or a tuple(sH,sW).Default: 1
padding: a tuple (paddingLeft, paddingRight, paddingTop, paddingBottom).
dilation: the spacing between kernel elements. Can be a single number or a tuple(dH,dW).Default: 1
Activation: only support NONE/RELU/RELU_N1_TO_1/RELU6
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,28,28,4),name='input0')
in1 = sgs_chalk.Input((8,3,3,4),name='input1')
out0 = sgs_chalk.Conv2d(in0,in1,name='output')
model = sgs_chalk.Model([in0,in1],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
input1 = np.zeros((8,3,3,4), dtype=np.float32)
in0 = sgs_chalk.Input((1,28,28,4),name='input0')
out0 = sgs_chalk.Conv2d(in0,input1,bias = None, Activation = 'RELU',name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Conv3d:
Args:
x : input tensor of shape(1, iD, iH, iW,in_channels)
weight: filters of shape(kD, kH, kW, in_channels,out_channels)
bias: optional bias tensor of shape(out_channels).Default:None
stride: the stride of the convolving kernel. Can be a single number or a tuple(sD,sH,sW).Default: 1
padding: a tuple (paddingI,paddingL,paddingT,paddingO,paddingR,paddingB).
dilation: the spacing between kernel elements. Can be a single number or a tuple(dD,dH,dW).Default: 1
Activation: only support NONE/RELU/RELU_N1_TO_1/RELU6
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input1 = np.zeros((3,3,3,64,64), dtype=np.float32)
in0 = sgs_chalk.Input((1,16,56,56,64),name='input0')
out0 = sgs_chalk.Add(in0,0.4)
out1 = sgs_chalk.Conv3d(out0,input1,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Cos:
Returns Cos(x) element-wise.
Args:
x: A `Tensor`. Must be Variable Tensor.
Returns:
```text
A Variable `Tensor`. Has the same shape as `x`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Sin(in0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- CustomNotEqual:
FLT_EPSILON = (1.192092896e-07F) if (fabs(x0 - value) < FLT_EPSILON) Output = x0 else Output = x1
Args:
x0: `Tensor`. Must be Variable Tensor.
x1: `Tensor`. Must be Variable Tensor, has same shape as x0.
name: A name for the model output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as input x0.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
from numpy import random as nr
input0 = sgs_chalk.Input((1,224,224,3),name='input0')
input1 = sgs_chalk.Input((1,224,224,3),name='input1')
out = sgs_chalk.CustomNotEqual(input0,input1,1.0,name='output')
model = sgs_chalk.Model([input0,input1], out)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True,inputs='RAWDATA')
- CustomPow:
Args:
input: x `Tensor`. Must be Variable Tensor.
input: y `Tensor`. Must be Constant Scaler.
name: A name for the model output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as input.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input = sgs_chalk.Input((14,3,41,2,1,2,3,5), name='input')
input1 = sgs_chalk.Input(0.3333333333333333, name='input1')
customPow_out = sgs_chalk.CustomPow(input,input1, name='customPow_out')
model = sgs_chalk.Model([input,], customPow_out)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)
- CustomizedScatterND:
Args:
input: A `Tensor`. Must be Variable Tensor whose rank r >= 1.
indices: A const Tensor or numpy.array whose rank q >= 1.
update: A Tensor whose rank is q+r-indices.shape[-1]-1
name: A name for the model output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as input.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input = sgs_chalk.Input((14,3,41,2,1,2,3,5), name='input')
indices = np.array([[5, 0, 1], [10, 2, 33]])
update = sgs_chalk.Input((2,2,1,2,3,5), name='update')
scatterND_out = sgs_chalk.CustomizedScatterND(input, indices, update, 0, name='scatterND_out')
model = sgs_chalk.Model([input,update], scatterND_out)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)
- Customized_Maxpooling:
Performs the max pooling on the input. Each entry in output
is the mean of the corresponding size ksize
window in value
and index.
Args:
x: A 4-D `Tensor` of shape `[batch, height, width, channels]`
ksize: A list of `ints` that has length `1`, `2` or `4`. The size of
the window for each dimension of the input tensor.
strides: An int or list of `ints` that has length `1`, `2` or `4`. The
stride of the sliding window for each dimension of the input tensor.
padding: a tuple (paddingLeft, paddingRight, paddingTop, paddingBottom).
name: Optional name for the operation.
Returns:
The max pooled output tensor
index tensor
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,28,28,4),name='input0')
output_list = sgs_chalk.Customized_Maxpooling(in0,[2,2],name=['output','index'])
model = sgs_chalk.Model([in0],output_list)
model.save('test.sim')
- DepthWiseConv2D:
DepthWiseConv2D
Args:
x : input tensor of shape(1, iH, iW,in_channels)
weight: filters of shape(1, kH, kW, out_channels) in_channels = out_channels
bias: optional bias tensor of shape(out_channels).Default:None
stride: the stride of the convolving kernel. Can be a single number or a tuple(sH,sW).Default: 1
padding: a tuple (paddingLeft, paddingRight, paddingTop, paddingBottom).
dilation: the spacing between kernel elements. Can be a single number or a tuple(dH,dW).Default: 1
Activation: only support NONE/RELU/RELU_N1_TO_1/RELU6
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,28,28,4),name='input0')
in1 = sgs_chalk.Input((1,3,3,4),name='input1')
out0 = sgs_chalk.DepthWiseConv2D(in0,in1,name='output')
model = sgs_chalk.Model([in0,in1],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
input1 = np.zeros((1,3,3,4), dtype=np.float32)
in0 = sgs_chalk.Input((1,28,28,4),name='input0')
out0 = sgs_chalk.DepthWiseConv2D(in0,input1,bias = None, Activation = 'RELU',name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Dilation:
Dilation a tensor.
Args:
tensor: A `Tensor`.
name: A name for the operation (optional).
Returns:
A `Tensor`. Has the same type as `tensor`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Dilation(in0,[2,1,0,0],[2,0],name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Div:
Returns x / y element-wise.
Args:
x: A `Tensor`. Must be Variable Tensor.
y: A `Tensor` or `numpy.ndarray`. Must have the same type as `x`, can be Variable or Const Tensor.
Support inner most dimension broadcasting.
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as `x`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
in1 = sgs_chalk.Input((28,512),name='input1')
out0 = sgs_chalk.Div(in0,in1,name='output')
model = sgs_chalk.Model([in0,in1],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Div(in0,5.0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
case2
from calibrator_custom import sgs_chalk
import numpy as np
input1 = np.ones((28,512), dtype=np.float32)
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Div(in0,input1,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- DmaCoefMatrix:
Args:
input: input `Tensor`. Must be Variable Tensor.
name: A name for the model output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as input.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input = sgs_chalk.Input((1,75,75,3), name='input')
dmacoefmatrix_out = sgs_chalk.DmaCoefMatrix(input, name='dmacoefmatrix_out')
model = sgs_chalk.Model([input], dmacoefmatrix_out)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)
- Elu:
Args:
x: A `Tensor`. Must be Variable Tensor.
name: A name for the model Input tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as settings.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Elu(in0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- Equal:
Returns the truth value of (x == y) element-wise.
Args:
x: A `Tensor`. Must be Variable Tensor.
y: A `Tensor` or `numpy.ndarray`. Must have the same type as `x`, can be Variable or Const Tensor.
Support inner most dimension broadcasting.
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as `x`.Tensor` of type `bool
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
in1 = sgs_chalk.Input((28,512),name='input1')
out0 = sgs_chalk.Equal(in0,in1,name='output')
model = sgs_chalk.Model([in0,in1],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Equal(in0,5.0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
case2
from calibrator_custom import sgs_chalk
import numpy as np
input1 = np.zeros((28,512), dtype=np.float32)
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Equal(in0,input1,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Erf:
Computes the Gauss error function of x
element-wise.
Args:
x: A `Tensor`. Must be Variable Tensor.
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`. has the same shape as x
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input = sgs_chalk.Input((1,36,2048), name='input')
output = sgs_chalk.Erf(input,name='output')
model = sgs_chalk.Model([input,], output)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)
- Exp:
Computes exponential of x element-wise. (y = e^x).
Args:
x: A `Tensor`. Must be Variable Tensor.
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as `x`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Exp(in0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Fix2Float:
Convert fix to float.
Args:
x: A `Tensor`. Must be Variable Tensor.
name: A name for the model Input tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as settings.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Fix2Float(in0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Floor:
Floor the values of a tensor to the nearest integer, element-wise.
Args:
x: A `Tensor`
Returns:
A `Tensor` of same shape and type as `x`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Floor(in0,name='output')
model = sgs_chalk.Model([in0],[out0])
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- Fullyconnected:
fully_connected
creates a variable called weights
, representing a fully connected weight matrix, which is multiplied by the inputs
to produce a Tensor
of hidden units.
Args:
x : input tensor of shape 2 dims
weight: filters of shape 2 dims
bias: optional bias tensor of shape(out_channels).Default:None
Activation: only support NONE/RELU/RELU_N1_TO_1/RELU6
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input1 = np.zeros((1000,112), dtype=np.float32)
in0 = sgs_chalk.Input((3,112),name='input0')
out0 = sgs_chalk.Fullyconnected(in0,input1,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
input1 = np.zeros((1000,112), dtype=np.float32)
in0 = sgs_chalk.Input((3,112),name='input0')
out0 = sgs_chalk.Fullyconnected(in0,input1,bias = None, Activation = 'RELU',name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- GRU:
Applies a multi-layer gated recurrent unit (GRU) RNN to an input sequence.
Args:
x: A `Tensor`,shape is (L,1,N,input_size) N=batch size L=sequence length
h0:tensor of shape(1,1,1,hidden_size),containing the initial hidden state for each element in the input sequence.
hidden_size : The number of features in the hidden state h
cn_output: whether output cn ,default false.
W: A `Tensor`, shape is [1,3*hidden_size,input_size]
R: A `Tensor`, shape is [1,3*hidden_size,hidden_size]
B: A `Tensor`, shape is [1,6*hidden_size]
Returns:
A `Tensor` list,usually concatenate op should be add after GRU
Examples:
case0
W_1 = np.ones((1,6,2))
R_1 = np.ones((1,6,2))
B_1 = np.ones((1,12))
in0 = sgs_chalk.Input((2,1,1,2),name='input0')
input1 = np.zeros((1,1,1,2), dtype=np.float32)
output_tensor_list= sgs_chalk.GRU(in0,input1,hidden_size=2,W=W_1,R=R_1,B=B_1,name=['gru_output0','gru_output1'])
out_1 = sgs_chalk.Concatenation([output_tensor_list[0],output_tensor_list[1]],axis=0,name="output0")
model = sgs_chalk.Model([in0],[out_1])
model.save('test.sim')
case1
W_1 = np.ones((1,6,2))
R_1 = np.ones((1,6,2))
B_1 = np.ones((1,12))
in0 = sgs_chalk.Input((2,1,1,2),name='input0')
input1 = np.zeros((1,1,1,2), dtype=np.float32)
output_tensor_list= sgs_chalk.GRU(in0,input1,hidden_size=2,W=W_1,R=R_1,B=B_1,name=['gru_output0','gru_output1'])
out_1 = sgs_chalk.Concatenation([output_tensor_list[0],output_tensor_list[1]],axis=0,name="output0")
output_tensor_list_1= sgs_chalk.GRU(out_1,input1,hidden_size=2,W=W_1,R=R_1,B=B_1,name=['gru_output2','gru_output3'])
out_2 = sgs_chalk.Concatenation([output_tensor_list_1[0],output_tensor_list_1[1]],axis=0,name="output1")
model = sgs_chalk.Model([in0],[out_2])
model.save('test.sim',input_config='./input_config.ini', convert_fixed=True, inputs='RAWDATA')
- Gather:
Gather slices from x
axis axis
according to indices
.
indices
must be an integer tensor of any dimension (usually 0-D or 1-D). Produces an output tensor with shape params.shape[:axis] + indices.shape + params.shape[axis + 1:]
Args:
x: A variable `Tensor`. The tensor from which to gather values.
indices: A `Tensor`. Must be in range `[0, params.shape[axis])`.
axis: A `Tensor`. The axis in `params` to gather `indices` from. Defaults to the first
dimension.
name: A name for the operation (optional).
Returns:
A `Tensor`. Has the same type as `value`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512,4),name='input0')
out0 = sgs_chalk.Gather(in0,[0,2],name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512,4),name='input0')
out0 = sgs_chalk.Gather(in0,[[0,1],[0,1]],axis=1,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Gelu:
out = input*0.5*(1.0+erff(input/sqrtf(2.0)))
Args:
x1: A `Tensor`
name: A name for the model output tensor (optional).
Returns:
A `Tensor`
case0
from calibrator_custom import sgs_chalk
import numpy as np
input1 = sgs_chalk.Input((1,224,224,3), name='input0')
out = sgs_chalk.Gelu(input1,name='output')
model = sgs_chalk.Model([input1], out)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)
- Greater:
greater(x, y, name=None) Returns the truth value of (x > y) element-wise.
Args:
x: A `Tensor`.
y: A `Tensor`. Must have the same type as `x`.
name: A name for the operation (optional).
Returns:
A `Tensor` of type `bool`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
in1 = sgs_chalk.Input((28,512),name='input1')
out0 = sgs_chalk.Greater(in0,in1,name='output')
model = sgs_chalk.Model([in0,in1],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Greater(in0,5.0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
case2
from calibrator_custom import sgs_chalk
import numpy as np
input1 = np.zeros((28,512), dtype=np.float32)
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Greater(in0,input1,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- GreaterEqual:
Returns the truth value of (x >= y) element-wise.
Args:
x: A `Tensor`. Must be Variable Tensor.
y: A `Tensor` or `numpy.ndarray`. Must have the same type as `x`, can be Variable or Const Tensor.
Support inner most dimension broadcasting.
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as `x`.Tensor` of type `bool
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
in1 = sgs_chalk.Input((28,512),name='input1')
out0 = sgs_chalk.GreaterEqual(in0,in1,name='output')
model = sgs_chalk.Model([in0,in1],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.GreaterEqual(in0,5.0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
case2
from calibrator_custom import sgs_chalk
import numpy as np
input1 = np.zeros((28,512), dtype=np.float32)
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.GreaterEqual(in0,input1,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- GroupConv:
GroupConv
Args:
x : input tensor of shape(1, iH, iW,in_channels)
weight: filters of shape(out_channels, kH, kW, in_channels)
bias: optional bias tensor of shape(out_channels).Default:None
stride: the stride of the convolving kernel. Can be a single number or a tuple(sH,sW).Default: 1
padding: a tuple (paddingLeft, paddingRight, paddingTop, paddingBottom).
dilation: the spacing between kernel elements. Can be a single number or a tuple(dH,dW).Default: 1
group: controls the connections between inputs and outputs. in_channels and out_channels must both be divisible by groups. Default: 1
Activation: only support NONE/RELU/RELU_N1_TO_1/RELU6
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input1 = np.zeros((8,3,3,2), dtype=np.float32)
in0 = sgs_chalk.Input((1,28,28,4),name='input0')
out0 = sgs_chalk.GroupConv(in0,input1,group=2,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Input:
As an entry point into a graph.
Args:
shape: `Tuple`.
name: A name for the model Input tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as settings.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),datatype='complex64', name='input0')
- Instancenorm:
Instancenorm
Args:
x: A `Tensor`
axis: Dimension along which to normalize. A scalar or a vector of
integers.
epsilon: A lower bound value for the norm.
weight: One dim,The value is x.shape[-1]
bias: One dim,The value is x.shape[-1]
Returns:
A `Tensor`,has the same shape as x
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
from numpy import random as nr
import pdb
#in0 = sgs_chalk.Input((4,256,96),name='input0')
weight = nr.uniform(-1, 1, (96)).astype('float32')
bias = nr.uniform(-1, 1, (96)).astype('float32')
in0 = sgs_chalk.Input((4,256,96),name='input0')
# weight = np.ones((96), dtype=np.float32)
# bias = np.ones((96), dtype=np.float32)
out0 = sgs_chalk.Instancenorm(in0,axis=[1],weight=weight,bias=bias,name='output')
model = sgs_chalk.Model([in0],[out0])
#model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
model.save('test.sim',input_config='./input_config.ini', convert_fixed=True, inputs='RAWDATA')
- L2Norm:
Normalizes along dimension axis
using an L2 norm.
For a 1-D tensor with axis = 0
, computes
output = x / sqrt(max(sum(x**2), epsilon))
For x
with more dimensions, independently normalizes each 1-D slice along dimension axis
.
Args:
x: A `Tensor`
axis: Dimension along which to normalize. A scalar or a vector of
integers.
Returns:
A `Tensor`
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,224,224,3),name='input0')
out0 = sgs_chalk.L2Norm(in0,[1,2],name='output')
model = sgs_chalk.Model([in0],[out0])
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True,inputs='RAWDATA')
- LSTM:
Applies a multi-layer long short-term memory (LSTM) RNN to an input sequence.
Args:
x: A `Tensor`,shape is (L,1,N,input_size) N=batch size L=sequence length
h0:tensor of shape(1,1,1,hidden_size),containing the initial hidden state for each element in the input sequence.
c0:tensor of shape(1,1,1,hidden_size),containing the initial cell state for each element in the input sequence.
hidden_size : The number of features in the hidden state h
cn_output: whether output cn ,default false.
W: A `Tensor`, shape is [1,4*hidden_size,input_size]
R: A `Tensor`, shape is [1,4*hidden_size,hidden_size]
B: A `Tensor`, shape is [1,8*hidden_size]
Returns:
A `Tensor` list,usually concatenate op should be add after LSTM
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
from numpy import random as nr
import pdb
from collections import OrderedDict
W_1 = np.ones((1,128,48))
R_1 = np.ones((1,128,32))
B_1 = np.ones((1,256))
W_2 = np.ones((1,64,32))
R_2 = np.ones((1,64,16))
B_2 = np.ones((1,128))
in0 = sgs_chalk.Input((2,1,1,48),name='input0')
input1 = np.zeros((1,1,1,32), dtype=np.float32)
input2 = np.zeros((1,1,1,32), dtype=np.float32)
input3 = np.zeros((1,1,1,16), dtype=np.float32)
input4 = np.zeros((1,1,1,16), dtype=np.float32)
output_tensor_list = sgs_chalk.LSTM(in0,input1,input2,hidden_size=32,W=W_1,R=R_1,B=B_1,name=['lstm_output0','lstm_output1'])
out_1 = sgs_chalk.Concatenation([output_tensor_list[0],output_tensor_list[1]],axis=0,name="output0")
output_tensor_list_1 = sgs_chalk.LSTM(out_1,input3,input4,hidden_size=16,W=W_2,R=R_2,B=B_2,name=['lstm1_output0','lstm1_output1'])
out_2 = sgs_chalk.Concatenation(output_tensor_list_1,axis=0,name="output0_0")
model = sgs_chalk.Model([in0],out_2)
#model.save('test.sim')
model.save('test.sim',input_config='./input_config.ini', convert_fixed=True, inputs='RAWDATA')
case1
from calibrator_custom import sgs_chalk
import numpy as np
from numpy import random as nr
import pdb
from collections import OrderedDict
W_1 = np.ones((1,128,48))
R_1 = np.ones((1,128,32))
B_1 = np.ones((1,256))
in0 = sgs_chalk.Input((2,1,1,48),name='input0')
input1 = np.zeros((1,1,1,32), dtype=np.float32)
input2 = np.zeros((1,1,1,32), dtype=np.float32)
output_tensor_list= sgs_chalk.LSTM(in0,input1,input2,hidden_size=32,cn_output=True,W=W_1,R=R_1,B=B_1,name=['lstm_output0','lstm_output1'])
out_1 = sgs_chalk.Concatenation([output_tensor_list[0],output_tensor_list[1]],axis=0,name="output0")
model = sgs_chalk.Model([in0],[out_1,output_tensor_list[2]])
model.save('test.sim',input_config='./input_config.ini', convert_fixed=True, inputs='RAWDATA')
- Layernorm:
Layernorm
Args:
x: A `Tensor`
axis: Dimension along which to normalize. A scalar or a vector of
integers.
epsilon: A lower bound value for the norm.
weight: One dim,The value is multiplied by the shape of the corresponding dimension on the axis
bias: One dim,The value is multiplied by the shape of the corresponding dimension on the axis
Returns:
A `Tensor`,has the same shape as x
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
from numpy import random as nr
import pdb
#in0 = sgs_chalk.Input((4,256,96),name='input0')
weight = nr.uniform(-1, 1, (96)).astype('float32')
bias = nr.uniform(-1, 1, (96)).astype('float32')
in0 = sgs_chalk.Input((4,256,96),name='input0')
# weight = np.ones((96), dtype=np.float32)
# bias = np.ones((96), dtype=np.float32)
out0 = sgs_chalk.Layernorm(in0,axis=[2],weight=weight,bias=bias,name='output')
model = sgs_chalk.Model([in0],[out0])
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
#model.save('test.sim',input_config='./input_config.ini', convert_fixed=True, inputs='RAWDATA')
- LeakyRelu:
Compute the Leaky ReLU activation function.
Args:
tensor: A `Tensor`.
alpha: Slope of the activation function at x < 0.
name: A name for the operation (optional).
Returns:
A `Tensor`. Has the same type as `tensor`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.LeakyRelu(in0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Less:
greater(x, y, name=None) Returns the truth value of (x < y) element-wise.
Args:
x: A `Tensor`.
y: A `Tensor`. Must have the same type as `x`.
name: A name for the operation (optional).
Returns:
A `Tensor` of type `bool`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
in1 = sgs_chalk.Input((28,512),name='input1')
out0 = sgs_chalk.Less(in0,in1,name='output')
model = sgs_chalk.Model([in0,in1],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Less(in0,5.0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
case2
from calibrator_custom import sgs_chalk
import numpy as np
input1 = np.zeros((28,512), dtype=np.float32)
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Less(in0,input1,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Log:
Args:
tensor: A `Tensor`.
name: A name for the operation (optional).
Returns:
A `Tensor`. Has the same type as `tensor`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Log(in0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- LogicalAnd:
Returns the truth value of x AND y element-wise.
Args:
x: A `Tensor`. Must be Variable Tensor.
y: A `Tensor` or `numpy.ndarray`. Must have the same type as `x`, can be Variable or Const Tensor.
Support inner most dimension broadcasting.
name: A name for the output tensor (optional).sss
Returns:
A Variable `Tensor`. Has the same shape as `x`.Tensor` of type `bool
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
in1 = sgs_chalk.Input((28,512),name='input1')
out0 = sgs_chalk.LogicalAnd(in0,in1,name='output')
model = sgs_chalk.Model([in0,in1],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.LogicalAnd(in0,1.0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
case2
from calibrator_custom import sgs_chalk
import numpy as np
input1 = np.zeros((28,512), dtype=np.float32)
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.LogicalAnd(in0,input1,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- LogicalNot:
Returns the truth value of NOT x element-wise.
Args:
x: A `Tensor`. Must be Variable Tensor.
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as `x`.Tensor` of type `bool
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.LogicalNot(in0,name='output')
model = sgs_chalk.Model(in0,out0)
model.save('test.sim')
- Logistic:
output = 1 / (1 + exp(-x))
Args:
tensor: A `Tensor`.
name: A name for the operation (optional).
Returns:
A `Tensor`. Has the same type as `tensor`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Logistic(in0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Max_Pool_2D:
Performs the max pooling on the input. Each entry in output
is the max of the corresponding size ksize
window in value
.
Args:
x: A 4-D `Tensor` of shape `[batch, height, width, channels]`
ksize: A list of `ints` that has length `1`, `2` or `4`. The size of
the window for each dimension of the input tensor.
strides: An int or list of `ints` that has length `1`, `2` or `4`. The
stride of the sliding window for each dimension of the input tensor.
padding: a tuple (paddingLeft, paddingRight, paddingTop, paddingBottom).
name: Optional name for the operation.
Returns:
The max pooled output tensor
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,112,112,3),name='input0')
out0 = sgs_chalk.Max_Pool_2D(in0,[2,2],name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- Max_Pool_3D:
Performs the average pooling on the input. Each entry in output
is the mean of the corresponding size ksize
window in value
.
Args:
x: A 5D `Tensor` of shape `[batch, height, width, channels]`
ksize: A list of `ints` that has length `3`. The size of
the window for each dimension of the input tensor.
strides: An int or list of `ints` that has length `3`. The
stride of the sliding window for each dimension of the input tensor.
padding: a tuple (paddingI,paddingL,paddingT,paddingO,paddingR,paddingB).
name: Optional name for the operation.
Returns:
The average pooled output tensor.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,3,28,28,4),name='input0')
out0 = sgs_chalk.Max_Pool_3D(in0,[2,2,2],name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Maximum:
Returns the max of x and y (i.e. x > y ? x : y) element-wise.
Args:
x: A `Tensor`. Must be Variable Tensor.
y: A `Tensor` or `numpy.ndarray`. Must have the same type as `x`, can be Variable or Const Tensor.
Support inner most dimension broadcasting.
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as `x`.Tensor` of type `bool
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
in1 = sgs_chalk.Input((28,512),name='input1')
out0 = sgs_chalk.Maximum(in0,in1,name='output')
model = sgs_chalk.Model([in0,in1],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Maximum(in0,1.0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
case2
from calibrator_custom import sgs_chalk
import numpy as np
input1 = np.zeros((28,512), dtype=np.float32)
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Maximum(in0,input1,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Mean:
Computes the mean of elements across dimensions of a tensor.
Reduces input_tensor
along the dimensions given in axis
.
Args:
tensor: A `Tensor`.
axis: The dimensions to reduce.
keep_dim:whether keep dim or not
name: A name for the operation (optional).
Returns:
A `Tensor`. The reduced tensor.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,28,28,512),name='input0')
out0 = sgs_chalk.Mean(in0,[1,2],name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Minimum:
Returns the min of x and y (i.e. x < y ? x : y) element-wise.
Args:
x: A `Tensor`. Must be Variable Tensor.
y: A `Tensor` or `numpy.ndarray`. Must have the same type as `x`, can be Variable or Const Tensor.
Support inner most dimension broadcasting.
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as `x`.Tensor` of type `bool
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
in1 = sgs_chalk.Input((28,512),name='input1')
out0 = sgs_chalk.Minimum(in0,in1,name='output')
model = sgs_chalk.Model([in0,in1],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Minimum(in0,1.0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
case2
from calibrator_custom import sgs_chalk
import numpy as np
input1 = np.zeros((28,512), dtype=np.float32)
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Minimum(in0,input1,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- MirrorPad:
MirrorPads a tensor.
This operation pads a tensor
according to the paddings
you specify. paddings
is an integer tensor with shape [n, 2]
, where n is the rank of tensor
. For each dimension D of input
, paddings[D, 0]
indicates how many values to add before the contents of tensor
in that dimension, and paddings[D, 1]
indicates how many values to add after the contents of tensor
in that dimension.
The padded size of each dimension D of the output is: paddings[D, 0] + tensor.dim_size(D) + paddings[D, 1]
Args:
tensor: A `Tensor`.
paddings: A `Tensor` of type `int32`.
name: A name for the operation (optional).
Returns:
A `Tensor`. Has the same type as `tensor`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Pad(in0,[[0,0],[10,10]],name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Mul:
Returns x * y element-wise.
Args:
x: A `Tensor`. Must be Variable Tensor.
y: A `Tensor` or `numpy.ndarray`. Must have the same type as `x`, can be Variable or Const Tensor.
Support inner most dimension broadcasting.
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as `x`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
in1 = sgs_chalk.Input((28,512),name='input1')
out0 = sgs_chalk.Mul(in0,in1,name='output')
model = sgs_chalk.Model([in0,in1],out0)
model.save('test.sim')
</details>
<details>
<summary>case1</summary>
```python
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Mul(in0,5.0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- MultiplyAdd:
output = input*multiply + add
Args:
x1: A `Tensor`
multiply_value: A `Value`
add_value: A `Value`
name: A name for the model output tensor (optional).
Returns:
A `Tensor`
case0
from calibrator_custom import sgs_chalk
import numpy as np
input1 = sgs_chalk.Input((1,1,36,2048), name='input0')
out = sgs_chalk.MultiplyAdd(input1,1.0,1.0,name='output')
model = sgs_chalk.Model([input1], out)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)
- Negative:
Computes the negative value of a tensor.
Given a tensor of integer or floating-point values, this operation returns a tensor of the same type, where each element contains the absolute value of the corresponding element in the input.
Args:
x: A `Tensor`
Returns:
A `Tensor` of same shape and type as `x`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Negative(in0,name='output')
model = sgs_chalk.Model([in0],[out0])
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- NotEqual:
Returns the truth value of (x != y) element-wise.
Args:
x: A `Tensor`. Must be Variable Tensor.
y: A `Tensor` or `numpy.ndarray`. Must have the same type as `x`, can be Variable or Const Tensor.
Support inner most dimension broadcasting.
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as `x`.Tensor` of type `bool
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
in1 = sgs_chalk.Input((28,512),name='input1')
out0 = sgs_chalk.NotEqual(in0,in1,name='output')
model = sgs_chalk.Model([in0,in1],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.NotEqual(in0,5.0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
case2
from calibrator_custom import sgs_chalk
import numpy as np
input1 = np.zeros((28,512), dtype=np.float32)
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.NotEqual(in0,input1,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- PSRoiPooling:
RoiPooling
Args:
x: A `Tensor`. Must be Variable Tensor.
RoiInfo: must be two dim, and the second dim is 5.
kernel_size : output kernel size.
spatial_scale ; A value
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`. shape is [RoiInfo.shape[0],kernel_size[0],kernel_size[1],x.shape[3]]
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input = sgs_chalk.Input((1,49,14,14,21), name='input')
RoiInfo = sgs_chalk.Input((300,5), name='input0')
output = sgs_chalk.PSRoiPooling(input,RoiInfo,[7,7], 0.0625,name='output')
model = sgs_chalk.Model([input,RoiInfo], output)
#model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True,inputs='RAWDATA')
- Pack:
Stacks a list of rank-R
tensors into one rank-(R+1)
tensor.
Packs the list of tensors in values
into a tensor with rank one higher than each tensor in values
, by packing them along the axis
dimension. Given a list of length N
of tensors of shape (A, B, C)
;
if axis == 0
then the output
tensor will have the shape (N, A, B, C)
. if axis == 1
then the output
tensor will have the shape (A, N, B, C)
. Etc.
Args:
x: A list of `Tensor` objects with the same shape and type. Must be Variable Tensor.
axis: An `int`. The axis to stack along. Defaults to the first dimension.
Negative values wrap around, so the valid range is `[-(R+1), R+1)`.
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512,1),name='input0')
in1 = sgs_chalk.Input((28,512,1),name='input1')
in2 = sgs_chalk.Input((28,512,1),name='input2')
x = [in0, in1, in2]
out0 = sgs_chalk.Pack(x,axis=2,name='output')
model = sgs_chalk.Model(x,out0)
model.save('test.sim')
- Pad:
Pads a tensor.
This operation pads a tensor
according to the paddings
you specify. paddings
is an integer tensor with shape [n, 2]
, where n is the rank of tensor
. For each dimension D of input
, paddings[D, 0]
indicates how many values to add before the contents of tensor
in that dimension, and paddings[D, 1]
indicates how many values to add after the contents of tensor
in that dimension.
The padded size of each dimension D of the output is: paddings[D, 0] + tensor.dim_size(D) + paddings[D, 1]
Args:
tensor: A `Tensor`.
paddings: A `Tensor` of type `int32`.
name: A name for the operation (optional).
Returns:
A `Tensor`. Has the same type as `tensor`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Pad(in0,[[0,0],[10,10]],name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512,512,4),name='input0')
out0 = sgs_chalk.Pad(in0,[[1,1],[2,2],[3,3],[4,4]],name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- PhaseModify:
if x0 > x1[0] Output = x0 + x1[1] else if x0 < x1[2] Output = x0 + x1[3]; else Output = x0
Args:
x0: `Tensor`. Must be Variable Tensor.
x1: A list. must include 4 elements.
name: A name for the model output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as input x0.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input0 = sgs_chalk.Input((1,224,224,3),name='input0')
out = sgs_chalk.PhaseModify(input0,[1.0,2.0,3.0,4.0],name='output')
model = sgs_chalk.Model([input0], out)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)
- PostProcess_Max:
sigmastar postprocess max
Args:
num_classes: number of classes
is_skip_background: please note background must be the first one
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
mbox_conf_softmax = sgs_chalk.Tensor(shape=model_config["input_shape"][1],name = model_config["input"][1])
cus_options = [(b"scores_lengh",21,"int"),
(b"skip",1,"int")]
postprocess_max_output_list = sgs_chalk.PostProcess_Max(mbox_conf_softmax,num_classes=21,skip=1)
model = sgs_chalk.Model([mbox_conf_softmax],postprocess_max_output_list)
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- PostProcess_Unpack:
sigmastar postprocess unpack
Args:
num_classes: number of classes
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,3249,6), name = 'x')
unpack_out_tensors1 = []
for i in range(4):
unpack_out_tensors1.append("SGS_unpack1_"+str(i))
output_list = sgs_chalk.PostProcess_Unpack(in0,scores_lengh=80,name=unpack_out_tensors1)
model = sgs_chalk.Model([in0],output_list)
#model.save('test.sim')
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- Prelu:
Parametric Rectified Linear Unit.
It follows: f(x) = alpha * x for x < 0, f(x) = x for x >= 0, where alpha
is a learned array with the same shape as x.
Args:
tensor: A `Tensor`.
slope: Slope of the activation function at x < 0.
name: A name for the operation (optional).
Returns:
A `Tensor`. Has the same type as `tensor`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Prelu(in0,5,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
input1 = np.zeros((512,), dtype=np.float32)
in0 = sgs_chalk.Input((3,28,512),name='input0')
out0 = sgs_chalk.Prelu(in0,5,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- RSqrt:
Computes square root of x element-wise. I.e., (y = rsqrt{x} ).
Args:
x: A `Tensor`
Returns:
A `Tensor` of same shape and type as `x`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.RSqrt(in0,name='output')
model = sgs_chalk.Model([in0],[out0])
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- Reciprocal:
Computes the Reciprocal value of a tensor.
Given a tensor of integer or floating-point values, this operation returns a tensor of the same type, where each element contains the absolute value of the corresponding element in the input.
Args:
x: A `Tensor`
Returns:
A `Tensor` of same shape and type as `x`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Reciprocal(in0,name='output')
model = sgs_chalk.Model([in0],[out0])
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- ReduceMax:
Computes the maxmum of elements across dimensions of a tensor.
Reduces input_tensor
along the dimensions given in axis
. Unless keepdims
is true, the rank of the tensor is reduced by 1 for each entry in axis
. If keepdims
is true, the reduced dimensions are retained with length 1.
Args:
input: A `Tensor` or 'Array'. Must be Variable Tensor if it's a Tensor.
asix: A `Tensor` or 'Array'. Must be Const Tensor if it's a Tensor.
keepdims: A one dimension array or list.
name: A name for the model output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as input.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,28,512,33),name='input0')
axis = np.array([-2,1],dtype=np.int32)
out0 = sgs_chalk.ReduceMax(in0, axis, keepdims=1, name='output')
model = sgs_chalk.Model([in0],out0)
model.save('reducemax.sim',input_config='./input_config.ini', convert_fixed=True, inputs='RAWDATA')
- ReduceMin:
Computes the minimum of elements across dimensions of a tensor.
Reduces input_tensor
along the dimensions given in axis
. Unless keepdims
is true, the rank of the tensor is reduced by 1 for each entry in axis
. If keepdims
is true, the reduced dimensions are retained with length 1.
Args:
input: A `Tensor` or 'Array'. Must be Variable Tensor if it's a Tensor.
asix: A `Tensor` or 'Array'. Must be Const Tensor if it's a Tensor.
keepdims: A one dimension array or list.
name: A name for the model output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as input.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,28,512,33),name='input0')
axis = np.array([-2,1],dtype=np.int32)
out0 = sgs_chalk.ReduceMin(in0, axis, keepdims=1, name='output')
model = sgs_chalk.Model([in0],out0)
model.save('reducemin.sim',input_config='./input_config.ini', convert_fixed=True, inputs='RAWDATA')
- ReduceSum:
Computes the sum of elements across dimensions of a tensor.
Reduces input_tensor
along the dimensions given in axis
. Unless keepdims
is true, the rank of the tensor is reduced by 1 for each entry in axis
. If keepdims
is true, the reduced dimensions are retained with length 1.
Args:
input: A `Tensor` or 'Array'. Must be Variable Tensor if it's a Tensor.
asix: A `Tensor` or 'Array'. Must be Const Tensor if it's a Tensor.
keepdims: A one dimension array or list.
name: A name for the model output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as input.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,28,512,33),name='input0')
axis = np.array([-2,1],dtype=np.int32)
out0 = sgs_chalk.ReduceSum(in0, axis, keepdims=1, name='output')
model = sgs_chalk.Model([in0],out0)
model.save('reducesum.sim',input_config='./input_config.ini', convert_fixed=True, inputs='RAWDATA')
- Relu:
Computes rectified linear: max(x, 0)
.
Args:
tensor: A `Tensor`.
name: A name for the operation (optional).
Returns:
A `Tensor`. Has the same type as `tensor`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Relu(in0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Relu6:
Computes Rectified Linear 6: `min(max(features, 0), 6)
Args:
tensor: A `Tensor`.
name: A name for the operation (optional).
Returns:
A `Tensor`. Has the same type as `tensor`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Relu6(in0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Relu_N1_TO_1:
Args:
tensor: A `Tensor`.
name: A name for the operation (optional).
Returns:
A `Tensor`. Has the same type as `tensor`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Relu_N1_TO_1(in0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Reshape:
As an entry point into a graph. reshape(a, newshape, order='C') Gives a new shape to an array without changing its data.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Reshape(in0,(28,256,2),name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Reshape(in0,(28,256,-1),name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- ResizeBilinear:
ResizeBilinear
Args:
x: A `Tensor`
size : output H w size
Returns:
A `Tensor`
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,224,224,3),name='input0')
out0 = sgs_chalk.ResizeBilinear(in0,[1120,1120],name='output')
model = sgs_chalk.Model([in0],[out0])
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- ResizeNearestNeighbor:
ResizeNearestNeighbor
Args:
x: A `Tensor`
size : output H w size
Returns:
A `Tensor`
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,224,224,3),name='input0')
out0 = sgs_chalk.ResizeNearestNeighbor(in0,[1120,1120],name='output')
model = sgs_chalk.Model([in0],[out0])
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True,inputs='RAWDATA')
- RoiPooling:
RoiPooling
Args:
x: A `Tensor`. Must be Variable Tensor.
RoiInfo: must be two dim, and the second dim is 5.
kernel_size : output kernel size.
spatial_scale ; A value
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`. shape is [RoiInfo.shape[0],kernel_size[0],kernel_size[1],x.shape[3]]
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input = sgs_chalk.Input((1,25,32,256), name='input')
RoiInfo = sgs_chalk.Input((304,5), name='input0')
output = sgs_chalk.RoiPooling(input,RoiInfo,[6,6], 0.0625,name='output')
model = sgs_chalk.Model([input,RoiInfo], output)
#model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True,inputs='RAWDATA')
- RootSumSquares2:
Output = sqrt(x0 * x0 + x1 * x1)
Args:
x0: `Tensor`. Must be Variable Tensor.only support int
x1: `Tensor`. Must be Variable Tensor,has same shape as x0.
name: A name for the model output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as input x0.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input0 = sgs_chalk.Input((1,224,224,3),name='input0')
input1 = sgs_chalk.Input((1,224,224,3),name='input1')
out = sgs_chalk.RootSumSquares2(input0,input1,name='output')
model = sgs_chalk.Model([input0,input1], out)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)
- Round:
Rounds the values of a tensor to the nearest integer, element-wise.
Args:
x: A `Tensor`
Returns:
A `Tensor` of same shape and type as `x`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Round(in0,name='output')
model = sgs_chalk.Model([in0],[out0])
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- Score_Filter:
Score_Filter
Args:
tensor: A `Tensor`.
name: A name for the operation (optional).
Returns:
A `Tensor`. Score index
A `Tensor`. valid box number
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,7875),name='input0')
out0,out1 = sgs_chalk.Score_Filter(in0,threshold=0.5,input_element_count=7875,name='output')
model = sgs_chalk.Model([in0],[out0,out1])
model.save('test.sim',input_config='./input_config.ini', convert_fixed=True)
- Select:
where(condition, x=None, y=None, name=None)
Return the elements, either from x
or y
, depending on the condition
. (deprecated) If both x
and y
are None, then this operation returns the coordinates of true elements of condition
. The coordinates are returned in a 2-D tensor where the first dimension (rows) represents the number of true elements, and the second dimension (columns) represents the coordinates of the true elements. Keep in mind, the shape of the output tensor can vary depending on how many true values there are in input. Indices are output in row-major order.
If both non-None, x
and y
must have the same shape. The condition
tensor must be a scalar if x
and y
are scalar. If x
and y
are vectors of higher rank, then condition
must be either a vector with size matching the first dimension of x
, or must have the same shape as x
.
The condition
tensor acts as a mask that chooses, based on the value at each element, whether the corresponding element / row in the output should be taken from x
(if true) or y
(if false).
If condition
is a vector and x
and y
are higher rank matrices, then it chooses which row (outer dimension) to copy from x
and y
. If condition
has the same shape as x
and y
, then it chooses which element to copy from x
and y
.
Args:
condition: A `Tensor` of type `float32`
x: A Tensor which may have the same shape as `condition`. If `condition` is
rank 1, `x` may have higher rank, but its first dimension must match the
size of `condition`.
y: A `tensor` with the same shape and type as `x`.
name: A name of the operation (optional)
Returns:
A `Tensor` with the same type and shape as `x`, `y` if they are non-None.
Otherwise, a `Tensor` with shape `(num_true, rank(condition))`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
in1 = sgs_chalk.Input((28,512),name='input1')
in2 = sgs_chalk.Input((28,512),name='input2')
out0 = sgs_chalk.Select(in0,in1,in2,name='output')
model = sgs_chalk.Model([in0,in1,in2],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
in1 = sgs_chalk.Input((28,512),name='input1')
out0 = sgs_chalk.Select(in0,5.0,in1,name='output')
model = sgs_chalk.Model([in0,in1],out0)
model.save('test.sim')
case2
from calibrator_custom import sgs_chalk
import numpy as np
input1 = np.zeros((28,512), dtype=np.float32)
in0 = sgs_chalk.Input((28,512),name='input0')
in1 = sgs_chalk.Input((28,512),name='input1')
out0 = sgs_chalk.Select(input1,in0,in1,name='output')
model = sgs_chalk.Model([in0,in1],out0)
model.save('test.sim')
- Shape:
Computes the shape of a tensor.
Given a tensor of integer or floating-point values, this operation returns a tensor of the same type, where each element contains the absolute value of the corresponding element in the input.
Args:
x: A `Tensor`
Returns:
A `Tensor` of same shape and type as `x`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Shape(in0,name='output')
model = sgs_chalk.Model([in0],[out0])
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- Silu:
Args:
input: A `Tensor`. Must be Variable Tensor.
name: A name for the model output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as input.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input = sgs_chalk.Input((14,3,41,2,1,2,3,5), name='input')
silu_out = sgs_chalk.Silu(input, name='silu_out')
model = sgs_chalk.Model([input,], silu_out)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)
- Sin:
Returns sin(x) element-wise.
Args:
x: A `Tensor`. Must be Variable Tensor.
Returns:
```text
A Variable `Tensor`. Has the same shape as `x`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Sin(in0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Slice:
Extracts a slice from a tensor.
This operation extracts a slice of size size
from a tensor input
starting at the location specified by begin
. The slice size
is represented as a tensor shape, where size[i]
is the number of elements of the 'i'th dimension of input
that you want to slice. The starting location (begin
) for the slice is represented as an offset in each dimension of input
. In other words, begin[i]
is the offset into the 'i'th dimension of input
that you want to slice from.
Args:
x: A `Tensor`. Must be Variable Tensor.
begin: const Tensor
size: const Tensor
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as `size`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Slice(in0,[0,0],[28,512],name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Slice(in0,[0,0],[14,510],name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Softmax:
Computes softmax activations.
Args:
tensor: A `Tensor`.
name: A name for the operation (optional).
Returns:
A `Tensor`. Has the same type as `tensor`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Softmax(in0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Softplus:
Args:
input: A `Tensor`. Must be Variable Tensor.
name: A name for the model output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as input.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input = sgs_chalk.Input((14,3,41,2,1,2,3,5), name='input')
softplus_out = sgs_chalk.Softplus(input, name='softplus_out')
model = sgs_chalk.Model([input,], softplus_out)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)
- Split:
Splits a tensor into sub tensors.
NumSplits is an integer, then value
is split along dimension axis
into NumSplits smaller tensors. This requires that NumSplits evenly divides value.shape[axis]
.
Args:
input: A `Tensor`. 1-D or higher.
NumSplits: an integer indicating the number of splits along split_dim
axis: An integer or scalar `int32` `Tensor`. The dimension along which to
split. Must be in the range `[-rank(value), rank(value))`. Defaults to 0.
name: A name for the operation (optional).
Returns:
returns `num_or_size_splits` `Tensor` objects;
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,4,4),name='input0')
output_list = sgs_chalk.Split(in0,NumSplits=2, axis=2,name=['output0','output1'])
model = sgs_chalk.Model([in0],output_list)
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- Split_V:
Splits a tensor into sub tensors.
Sizesplits is a 1-D Tensor (or list), and value is split into len(size_splits) elements. The shape of the i-th element has the same size as the value
except along dimension axis
where the size is size_splits[i].
Args:
input: A `Tensor`. 1-D or higher.
SizeSplits: Python list containing the sizes of each output tensor along split_dim.
the sum of sizes along the split dimension must match that of x
axis: An integer or scalar `int32` `Tensor`. The dimension along which to
split. Must be in the range `[-rank(value), rank(value))`. Defaults to 0.
name: A name for the operation (optional).
Returns:
returns `size_splits` `Tensor` objects;
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,4,4),name='input0')
output_list = sgs_chalk.Split_V(in0,SizeSplits=[1,2,1], axis=2,name=['output0','output1','output2'])
model = sgs_chalk.Model([in0],output_list)
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,4,3),name='input0')
output_list = sgs_chalk.Split_V(in0,SizeSplits=[2,2], axis=1,name=['output0','output1'])
model = sgs_chalk.Model([in0],output_list)
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- Sqrt:
Computes square root of x element-wise. I.e., (y = sqrt{x} = x^{½}).
Args:
x: A `Tensor`
Returns:
A `Tensor` of same shape and type as `x`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Sqrt(in0,name='output')
model = sgs_chalk.Model([in0],[out0])
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- Square:
Args:
input: A `Tensor`. Must be Variable Tensor.
name: A name for the model output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as input.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input = sgs_chalk.Input((14,3,41,2,1,2,3,5), name='input')
square_out = sgs_chalk.Square(input, name='softplus_out')
model = sgs_chalk.Model([input,], square_out)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)
- StridedSlice:
Extracts a strided slice of a tensor (generalized python array indexing).
Roughly speaking, this op extracts a slice of size (end-begin)/stride
from the given input_
tensor. Starting at the location specified by begin
the slice continues by adding stride
to the index until all dimensions are not less than end
. Note that a stride can be negative, which causes a reverse slice.
Given a Python slice input[spec0, spec1, ..., specn]
, this function will be called as follows.
begin
, end
, and strides
will be vectors of length n. n in general is not equal to the rank of the input_
tensor.
Args:
x: A `Tensor`. Must be Variable Tensor.
begin: const Tensor
size: const Tensor
begin_mask: An `int32` mask.
end_mask: An `int32` mask.
ellipsis_mask: An `int32` mask.
new_axis_mask: An `int32` mask.
shrink_axis_mask: An `int32` mask.
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as `x`. (end-begin)/stride
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512,4),name='input0')
out0 = sgs_chalk.StridedSlice(in0,[1,0,0],[28,512,4],[1,2,1],name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Sub:
Returns x - y element-wise.
Args:
x: A `Tensor`. Must be Variable Tensor.
y: A `Tensor` or `numpy.ndarray`. Must have the same type as `x`, can be Variable or Const Tensor.
Support inner most dimension broadcasting.
name: A name for the output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as `x`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
in1 = sgs_chalk.Input((28,512),name='input1')
out0 = sgs_chalk.Sub(in0,in1,name='output')
model = sgs_chalk.Model([in0,in1],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Sub(in0,5.0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Sum:
Computes the sum of elements across dimensions of a tensor.
Reduces input_tensor
along the dimensions given in axis
.
Args:
tensor: A `Tensor`.
axis: The dimensions to reduce.
keep_dim:whether keep dim or not
name: A name for the operation (optional).
Returns:
A `Tensor`. The reduced tensor.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,28,28,512),name='input0')
out0 = sgs_chalk.Sum(in0,[0,1,2,3],name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((1,28,28,512),name='input0')
out0 = sgs_chalk.Sum(in0,[1,2],name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- TFLite_Detection_NMS:
sigmastar postprocess nms
Args:
max_detection: max number pf output dectection bboxes
num_classes:number of classes
is_need_index : outputs include index or not
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
bosdecoder_output_list = sgs_chalk.BoxDecoder(config,output_list)
confidence_tensor = sgs_chalk.Logistic(output_list[4],name="confidence_tensor")
SGS_score0 = sgs_chalk.Logistic(output_list[5],name="score0_tensor")
SGS_score1 = sgs_chalk.Mul(confidence_tensor,SGS_score0,name="SGS_score1")
out1 = sgs_chalk.TFLite_Detection_NMS(bosdecoder_output_list[0],bosdecoder_output_list[1],bosdecoder_output_list[2],
bosdecoder_output_list[3],confidence_tensor,SGS_score1,output_list[6],mode='YOLO',
max_detections=100,nms_score_threshold=0.4,
nms_iou_threshold=0.45,num_classes=80,is_need_index=False)
case1
from calibrator_custom import sgs_chalk
import numpy as np
bosdecoder_output_list = sgs_chalk.BoxDecoder(config,output_list)
mbox_conf_softmax = sgs_chalk.Input(model_config["input_shape"][1], name = model_config["input"][1])
postprocess_max_output_list = sgs_chalk.PostProcess_Max(mbox_conf_softmax,scores_lengh=21,skip=1)
out1 = sgs_chalk.TFLite_Detection_NMS(bosdecoder_output_list[0],bosdecoder_output_list[1],bosdecoder_output_list[2],
bosdecoder_output_list[3],postprocess_max_output_list[0],postprocess_max_output_list[1],
mode='SSD',max_detections=10,nms_score_threshold=0.01,
nms_iou_threshold=0.45,num_classes=20,is_need_index=False)
- Tanh:
Args:
tensor: A `Tensor`.
name: A name for the operation (optional).
Returns:
A `Tensor`. Has the same type as `tensor`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512),name='input0')
out0 = sgs_chalk.Tanh(in0,name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- Tile:
Constructs a tensor by tiling a given tensor.
This operation creates a new tensor by replicating input
multiples
times. The output tensor's i'th dimension has input.dims(i) * multiples[i]
elements, and the values of input
are replicated multiples[i]
times along the 'i'th dimension. For example, tiling [a b c d]
by [2]
produces [a b c d a b c d]
.
Args:
input: A `Tensor`. 1-D or higher.
multiples: A `Tensor`. Length must be the same as the number of dimensions in `input`
name: A name for the operation (optional).
Returns:
A `Tensor`. Has the same type as `input`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512,4),name='input0')
out0 = sgs_chalk.Tile(in0,(1,1,2),name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
- TopK:
Args:
input: 1-D or higher `Tensor` with last dimension at least `k`.
k: 0-D `int32`. Number of top elements to look for along the last dimension (along each row for matrices).
use_value: 0 or 1. Whether the value output tensor has consumers.
use_index: 0 or 1. Whether the index output tensor has consumers.
name: A name for the model output tensor (optional).
Returns:
values: The `k` largest elements along each last dimensional slice.
indices: The indices of `values` within the last dimension of `input`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input = sgs_chalk.Input((1,36,2048), name='input')
output_list = sgs_chalk.TopK(input,k=[1], name=['value','index'])
model = sgs_chalk.Model([input,], output_list)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)
- Transpose:
Transposes x.
Permutes the dimensions according to perm
.
The returned tensor's dimension i will correspond to the input dimension perm[i]
. If perm
is not given, it is set to (n-1...0), where n is the rank of the input tensor. Hence by default, this operation performs a regular matrix transpose on 2-D input Tensors.
Args:
input: A `Tensor`. 1-D or higher.
perm: A permutation of the dimensions of `a`.
name: A name for the operation (optional).
Returns:
A transposed `Tensor`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512,4),name='input0')
out0 = sgs_chalk.Transpose(in0,(0,2,1),name='output')
model = sgs_chalk.Model([in0],out0)
model.save('test.sim')
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,512,4),name='input0')
in1 = sgs_chalk.Input((28,512,4),name='input1')
out0 = sgs_chalk.Add(in0,in1)
out1 = sgs_chalk.Transpose(out0,(0,2,1),name='output')
model = sgs_chalk.Model([in0,in1],out1)
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- Unpack:
Unpacks the given dimension of a rank-R
tensor into rank-(R-1)
tensors.
Unpacks num
tensors from value
by chipping it along the axis
dimension. If num
is not specified (the default), it is inferred from value
's shape. If value.shape[axis]
is not known, ValueError
is raised.
For example, given a tensor of shape (A, B, C, D)
;
If axis == 0
then the i'th tensor in output
is the slice value[i, :, :, :]
and each tensor in output
will have shape (B, C, D)
. (Note that the dimension unpacked along is gone, unlike split
).
If axis == 1
then the i'th tensor in output
is the slice value[:, i, :, :]
and each tensor in output
will have shape (A, C, D)
. Etc.
Args:
x: A `Tensor`. Must be Variable Tensor.
axis: An `int`. The axis to unstack along. Defaults to the first dimension.
Negative values wrap around, so the valid range is `[-R, R)
num: An `int`. The length of the dimension `axis`. Automatically inferred if
`None` (the default).
name: A name for the output tensor (optional).
Returns:
The list of `Tensor` objects unstacked from `value`.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,4,3),name='input0')
output_list = sgs_chalk.Unpack(in0,axis=2,name=['output0','output1','output2'])
model = sgs_chalk.Model([in0],output_list)
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
case1
from calibrator_custom import sgs_chalk
import numpy as np
in0 = sgs_chalk.Input((28,4,3),name='input0')
output_list = sgs_chalk.Unpack(in0,axis=1,name=['output0','output1','output2','output3'])
model = sgs_chalk.Model([in0],output_list)
model.save('test.sim',input_config='./input_config.ini',convert_fixed=True)
- WiggleErr:
Out = x2[0] * cos(2*atanx) + x2[1] * sin(2*atanx) + x2[2] * cos(4*atanx) + x2[3] * sin(4*atanx) + x2[4]; atanx can be 0 or 1.5707
Args:
x0: `Tensor`. Must be Variable Tensor.only support int
x1: `Tensor`. Must be Variable Tensor,has same shape as x0.only support int
x2: A list. must include 5 elements.
name: A name for the model output tensor (optional).
Returns:
A Variable `Tensor`. Has the same shape as input x0.
Examples:
case0
from calibrator_custom import sgs_chalk
import numpy as np
input0 = sgs_chalk.Input((1,224,224,3),name='input0')
input1 = sgs_chalk.Input((1,224,224,3),name='input1')
out = sgs_chalk.WiggleErr(input0,input1,[1.0,2.0,3.0,4.0,5.0],name='output')
model = sgs_chalk.Model([input0,input1], out)
model.save('test.sim', input_config='./input_config.ini', convert_fixed=True)