8 #ifndef UNITY_TOOLKITS_NEURAL_NET_MODEL_SPEC_HPP_ 9 #define UNITY_TOOLKITS_NEURAL_NET_MODEL_SPEC_HPP_ 17 #include <ml/neural_net/float_array.hpp> 18 #include <ml/neural_net/weight_init.hpp> 23 namespace Specification {
31 namespace neural_net {
67 model_spec(
const CoreML::Specification::NeuralNetwork& nn_model);
98 std::unique_ptr<CoreML::Specification::NeuralNetwork> move_coreml_spec() &&;
117 float_array_map export_params_view()
const;
129 void update_params(
const float_array_map& weights,
bool use_quantization =
false);
138 bool has_layer_output(
const std::string& layer_name)
const;
146 void add_relu(
const std::string& name,
const std::string& input);
155 void add_leakyrelu(
const std::string& name,
const std::string& input,
164 void add_sigmoid(
const std::string& name,
const std::string& input);
179 void add_pooling(
const std::string& name,
const std::string& input,
size_t kernel_height,
180 size_t kernel_width,
size_t stride_h,
size_t stride_w,
padding_type padding,
181 bool use_poolexcludepadding =
false,
pooling_type pooling = pooling_type::MAX);
195 void add_convolution(
const std::string& name,
const std::string& input,
196 size_t num_output_channels,
size_t num_kernel_channels,
197 size_t kernel_height,
size_t kernel_width,
199 weight_initializer weight_initializer_fn,
200 weight_initializer bias_initializer_fn =
nullptr);
213 void add_padding(
const std::string& name,
const std::string& input,
214 size_t padding_top,
size_t padding_bottom,
215 size_t padding_left,
size_t padding_right,
226 void add_upsampling(
const std::string& name,
const std::string& input,
227 size_t scaling_x,
size_t scaling_y);
240 void add_inner_product(
const std::string& name,
const std::string& input,
241 size_t num_output_channels,
size_t num_input_channels,
242 weight_initializer weight_initializer_fn,
243 weight_initializer bias_initializer_fn =
nullptr);
256 void add_batchnorm(
const std::string& name,
const std::string& input,
257 size_t num_channels,
float epsilon);
269 void add_instancenorm(
const std::string& name,
const std::string& input,
270 size_t num_channels,
float epsilon);
278 void add_channel_concat(
const std::string& name,
279 const std::vector<std::string>& inputs);
287 void add_softmax(
const std::string& name,
const std::string& input);
299 void add_flatten(
const std::string& name,
const std::string& input);
307 void add_addition(
const std::string& name,
308 const std::vector<std::string>& inputs);
316 void add_multiplication(
const std::string& name,
317 const std::vector<std::string>& inputs);
325 void add_exp(
const std::string& name,
const std::string& input);
337 void add_scale(
const std::string& name,
const std::string& input,
338 const std::vector<size_t>& shape_c_h_w,
339 weight_initializer scale_initializer_fn);
348 void add_constant(
const std::string& name,
349 const std::array<size_t, 3>& shape_c_h_w,
350 weight_initializer weight_initializer_fn);
359 void add_reshape(
const std::string& name,
const std::string& input,
360 const std::array<size_t, 4>& seq_c_h_w);
370 void add_permute(
const std::string& name,
const std::string& input,
371 const std::array<size_t, 4>& axis_permutation);
383 void add_channel_slice(
const std::string& name,
const std::string& input,
384 int start_index,
int end_index,
size_t stride);
401 void add_lstm(
const std::string& name,
const std::string& input,
402 const std::string& hidden_input,
const std::string& cell_input,
403 const std::string& hidden_output,
404 const std::string& cell_output,
size_t input_vector_size,
405 size_t output_vector_size,
float cell_clip_threshold,
416 void add_preprocessing(
const std::string& feature_name,
417 const float image_scale);
427 void add_transpose(
const std::string& name,
const std::string& input,
428 std::vector<size_t> axes);
439 void add_split_nd(
const std::string& name,
const std::string& input,
440 size_t axis,
size_t num_splits,
441 const std::vector<size_t>& split_sizes);
450 void add_concat_nd(
const std::string& name,
451 const std::vector<std::string>& inputs,
size_t axis);
460 void add_reshape_static(
const std::string& name,
const std::string& input,
461 const std::vector<size_t>& targetShape);
469 void add_reshape_dynamic(
const std::string& name,
470 const std::vector<std::string>& inputs);
479 void add_expand_dims(
const std::string& name,
const std::string& input,
480 const std::vector<size_t>& axes,
481 const std::vector<size_t>& inputVector,
482 const std::vector<size_t>& outputVector);
491 void add_squeeze(
const std::string& name,
const std::string& input,
492 const std::vector<size_t>& axes,
493 const std::vector<size_t>& inputVector,
494 const std::vector<size_t>& outputVector);
502 void add_add_broadcastable(
const std::string& name,
503 const std::vector<std::string>& inputs);
511 void add_gather(
const std::string& name,
512 const std::vector<std::string>& inputs);
521 void add_constant_nd(
const std::string& name,
522 const std::vector<size_t>& shape,
523 const weight_initializer& data);
531 void add_get_shape(
const std::string& name,
const std::string& input);
539 void add_slice_dynamic(
const std::string& name,
const std::vector<std::string>& inputs);
553 void add_nms_layer(
const std::string& name,
const std::vector<std::string>& inputs,
554 const std::vector<std::string>& outputs,
float iou_threshold,
555 float confidence_threshold,
size_t max_boxes,
bool per_class_supression);
558 std::unique_ptr<CoreML::Specification::NeuralNetwork> impl_;
569 pipeline_spec(std::unique_ptr<CoreML::Specification::Pipeline> impl);
592 std::unique_ptr<CoreML::Specification::Pipeline> move_coreml_spec() &&;
595 std::unique_ptr<CoreML::Specification::Pipeline> impl_;
601 #endif // UNITY_TOOLKITS_NEURAL_NET_MODEL_SPEC_HPP_
const CoreML::Specification::Pipeline & get_coreml_spec() const
const CoreML::Specification::NeuralNetwork & get_coreml_spec() const