def extract(node): proto_layer = node.pb param = proto_layer.correlation_param corr_type = 'caffe.CorrelationParameter.MULTIPLY' if param.correlation_type == 1: corr_type = 'caffe.CorrelationParameter.SUBTRACT' update_attrs = { 'pad': param.pad, 'kernel_size': param.kernel_size, 'max_displacement': param.max_displacement, 'stride_1': param.stride_1, 'stride_2': param.stride_2, 'single_direction': param.single_direction, 'do_abs': int(param.do_abs), 'correlation_type': corr_type, } mapping_rule = merge_attrs(param, update_attrs) mapping_rule.update(layout_attrs()) # update the attributes of the node Op.get_op_class_by_name(__class__.op).update_node_stat( node, mapping_rule) return __class__.enabled
def extract(node): proto_layer = node.pb param = proto_layer.resample_param types = [ "", 'caffe.ResampleParameter.NEAREST', 'caffe.ResampleParameter.LINEAR', 'caffe.ResampleParameter.CUBIC', 'caffe.ResampleParameter.AREA' ] resample_type = types[param.type] update_attrs = { 'antialias': int(param.antialias), 'height': param.height, 'width': param.width, 'type': resample_type, 'factor': param.factor } mapping_rule = merge_attrs(param, update_attrs) mapping_rule['resample_type'] = mapping_rule['type'] mapping_rule.pop('type') # update the attributes of the node Op.get_op_class_by_name(__class__.op).update_node_stat( node, mapping_rule) return __class__.enabled
def extract(cls, node): proto_layer = node.pb pb_model = node.model_pb param = proto_layer.prelu_param update_attrs = { 'channel_shared': int(param.channel_shared) } variance_norm_caffe_map = { 0: 'caffe.FillerParameter.FAN_IN', 1: 'caffe.FillerParameter.FAN_OUT', 2: 'caffe.FillerParameter.AVERAGE' } if hasattr(param, 'filler'): update_attrs.update({ 'filler_type': param.filler.type, 'filler_value': int(param.filler.value), 'min': int(param.filler.min), 'max': int(param.filler.max), 'mean': int(param.filler.mean), 'std': int(param.filler.std), 'sparse': param.filler.sparse, 'variance_norm': variance_norm_caffe_map[param.filler.variance_norm] }) mapping_rule = merge_attrs(param, update_attrs) mapping_rule.update(weights_biases(False, pb_model)) mapping_rule.update(layout_attrs()) # update the attributes of the node PReLU.update_node_stat(node, mapping_rule) return cls.enabled
def extract(node): proto_layer = node.pb param = proto_layer.region_yolo_param flatten_param = proto_layer.flatten_param axis = flatten_param.axis end_axis = flatten_param.end_axis coords = param.coords classes = param.classes num = param.num update_attrs = { 'coords': coords, 'classes': classes, 'num': num, 'do_softmax': int(param.do_softmax), 'anchors': np.array(param.anchors), 'mask': np.array(param.mask) } flatten_attrs = {'axis': axis, 'end_axis': end_axis} mapping_rule = merge_attrs(param, update_attrs) mapping_rule.update(flatten_attrs) mapping_rule.update(layout_attrs()) # update the attributes of the node Op.get_op_class_by_name(__class__.op).update_node_stat( node, mapping_rule) return __class__.enabled
def extract(cls, node): proto_layer = node.pb param = proto_layer.augmentation_param # slice_dim is deprecated parameter and is used as alias for axis # however if slice_dim is defined and axis is default, we use slice_dim update_attrs = { 'crop_width': param.crop_width, 'crop_height': param.crop_height, 'write_augmented': param.write_augmented, 'max_multiplier': param.max_multiplier, 'augment_during_test': int(param.augment_during_test), 'recompute_mean': param.recompute_mean, 'write_mean': param.write_mean, 'mean_per_pixel': int(param.mean_per_pixel), 'mean': param.mean, 'mode': param.mode, 'bottomwidth': param.bottomwidth, 'bottomheight': param.bottomheight, 'num': param.num, 'chromatic_eigvec': param.chromatic_eigvec } mapping_rule = merge_attrs(param, update_attrs) if node.model_pb: for index in range(0, len(node.model_pb.blobs)): embed_input(mapping_rule, index + 1, 'custom_{}'.format(index), node.model_pb.blobs[index].data) # update the attributes of the node DataAugmentationOp.update_node_stat(node, mapping_rule) return cls.enabled
def extract(cls, node): proto_layer = node.pb param = proto_layer.prior_box_param variance = param.variance if len(variance) == 0: variance = [0.1] update_attrs = { 'width': list(param.width), 'height': list(param.height), 'flip': int(param.flip), 'clip': int(param.clip), 'variance': list(variance), 'img_size': param.img_size, 'img_h': param.img_h, 'img_w': param.img_w, 'step': param.step, 'step_h': param.step_h, 'step_w': param.step_w, 'offset': param.offset, } mapping_rule = merge_attrs(param, update_attrs) mapping_rule.update(layout_attrs()) # update the attributes of the node PriorBoxClusteredOp.update_node_stat(node, mapping_rule) return cls.enabled
def extract(cls, node): proto_layer = node.pb param = proto_layer.eltwise_param input_len = len(node.in_edges()) eltwise_caffe_map = { 0: EltwiseNMul if input_len > 2 else Mul, 1: EltwiseNAdd if input_len > 2 else Add, 2: EltwiseNMax if input_len > 2 else Maximum, } operation = int(param.operation) if operation not in eltwise_caffe_map: raise Exception( 'Unsupported type of operation in Eltwise layer: ' + node.name) lin_op_class = eltwise_caffe_map[operation] mapping_rule = merge_attrs(param, {'coeff': np.array(param.coeff)}) mapping_rule.update(layout_attrs()) assert len(param.coeff) <= input_len lin_op_class.update_node_stat(node, mapping_rule) return cls.enabled
def extract(node): proto_layer = node.pb param = proto_layer.resample_param types = [ "", 'nearest', 'linear', 'cubic', 'area', ] resample_type = types[param.type] update_attrs = { 'antialias': int(param.antialias), 'height': param.height, 'width': param.width, 'type': resample_type, 'factor': param.factor, 'fw': 'caffe', } mapping_rule = merge_attrs(param, update_attrs) mapping_rule['mode'] = mapping_rule['type'] mapping_rule['axes'] = int64_array([2, 3]) mapping_rule.pop('type') Interpolate.update_node_stat(node, mapping_rule) return __class__.enabled
def extract(node): proto_layer = node.pb param = proto_layer.prior_box_param variance = param.variance if len(variance) == 0: variance = [0.1] update_attrs = { 'aspect_ratio': np.array(param.aspect_ratio), 'min_size': np.array(param.min_size), 'max_size': np.array(param.max_size), 'flip': int(param.flip), 'clip': int(param.clip), 'variance': list(variance), 'img_size': param.img_size, 'img_h': param.img_h, 'img_w': param.img_w, 'step': param.step, 'step_h': param.step_h, 'step_w': param.step_w, 'offset': param.offset, } mapping_rule = merge_attrs(param, update_attrs) mapping_rule.update(layout_attrs()) # update the attributes of the node Op.get_op_class_by_name(__class__.op).update_node_stat( node, mapping_rule) return __class__.enabled
def extract(cls, node): proto_layer = node.pb param = proto_layer.tile_param mapping_rule = { 'axis': int(param.axis), 'tiles': int(param.tiles), } mapping_rule = merge_attrs(param, mapping_rule) AttributedTile.update_node_stat(node, mapping_rule) return cls.enabled
def extract(node): proto_layer = node.pb param = proto_layer.tile_param mapping_rule = { 'axis': int(param.axis), 'tiles': int(param.tiles), } mapping_rule = merge_attrs(param, mapping_rule) # update the attributes of the node Op.get_op_class_by_name(__class__.op).update_node_stat( node, mapping_rule) return __class__.enabled
def extract(cls, node): proto_layer = node.pb param = proto_layer.ctc_decoder_param update_attrs = {'ctc_merge_repeated': (int)(param.ctc_merge_repeated)} mapping_rule = merge_attrs(param, update_attrs) mapping_rule.update(layout_attrs()) # update the attributes of the node CTCGreedyDecoderOp.update_node_stat(node, mapping_rule) return cls.enabled
def extract(cls, node): proto_layer = node.pb param = proto_layer.grn_param update_attrs = { 'bias': param.bias, } mapping_rule = merge_attrs(param, update_attrs) # update the attributes of the node GRNOp.update_node_stat(node, mapping_rule) return cls.enabled
def extract(node): proto_layer = node.pb param = proto_layer.grn_param update_attrs = { 'bias': param.bias, } mapping_rule = merge_attrs(param, update_attrs) # update the attributes of the node Op.get_op_class_by_name(__class__.op).update_node_stat(node, mapping_rule) return __class__.enabled
def extract(node): proto_layer = node.pb param = proto_layer.ctc_decoder_param update_attrs = {'ctc_merge_repeated': (int)(param.ctc_merge_repeated)} mapping_rule = merge_attrs(param, update_attrs) mapping_rule.update(layout_attrs()) # update the attributes of the node Op.get_op_class_by_name(__class__.op).update_node_stat( node, mapping_rule) return __class__.enabled
def extract(cls, node): proto_layer = node.pb param = proto_layer.reorg_yolo_param stride = param.stride update_attrs = { 'stride': stride, } mapping_rule = merge_attrs(param, update_attrs) mapping_rule.update(layout_attrs()) # update the attributes of the node ReorgYoloOp.update_node_stat(node, mapping_rule) return cls.enabled
def extract(cls, node): proto_layer = node.pb param = proto_layer.argmax_param update_attrs = { 'out_max_val': int(param.out_max_val), 'top_k': param.top_k, 'axis': param.axis, } mapping_rule = merge_attrs(param, update_attrs) ArgMaxOp.update_node_stat(node, mapping_rule) # ArgMax must be converted to TopK but without the output with values ArgMaxOp.update_node_stat(node, {'remove_values_output': True}) return cls.enabled
def extract(node): proto_layer = node.pb param = proto_layer.reorg_yolo_param stride = param.stride update_attrs = { 'stride': stride, } mapping_rule = merge_attrs(param, update_attrs) mapping_rule.update(layout_attrs()) # update the attributes of the node Op.get_op_class_by_name(__class__.op).update_node_stat( node, mapping_rule) return __class__.enabled
def extract(node): proto_layer = node.pb param = proto_layer.interp_param update_attrs = { 'height': param.height, 'width': param.width, 'zoom_factor': param.zoom_factor, 'shrink_factor': param.shrink_factor, } mapping_rule = merge_attrs(param, update_attrs) mapping_rule.update({'fw': 'caffe', 'mode': 'linear', 'axes': int64_array([2, 3]), 'pads_begin': param.pad_beg, 'pads_end': param.pad_end, 'align_corners': 1}) Interpolate.update_node_stat(node, mapping_rule) return __class__.enabled
def extract(node): proto_layer = node.pb param = proto_layer.argmax_param update_attrs = { 'out_max_val': int(param.out_max_val), 'top_k': param.top_k, 'axis': param.axis } mapping_rule = merge_attrs(param, update_attrs) # update the attributes of the node Op.get_op_class_by_name(__class__.op).update_node_stat( node, mapping_rule) return __class__.enabled
def extract(node): proto_layer = node.pb param = proto_layer.psroi_pooling_param update_attrs = { 'spatial_scale': param.spatial_scale, 'output_dim': param.output_dim, 'group_size': param.group_size, } mapping_rule = merge_attrs(param, update_attrs) mapping_rule.update(layout_attrs()) # update the attributes of the node Op.get_op_class_by_name(__class__.op).update_node_stat(node, mapping_rule) return __class__.enabled
def slice_ext(proto_layer, model_layer): param = proto_layer.slice_param # slice_dim is deprecated parameter and is used as alias for axis # however if slice_dim is defined and axis is default, we use slice_dim if param.slice_dim != 1 and param.axis == 1: axis = param.slice_dim else: axis = param.axis update_attrs = { 'axis': axis, 'slice_point': param.slice_point, } mapping_rule = merge_attrs(param, update_attrs) if 'slice_point' not in mapping_rule: mapping_rule['slice_point'] = [] mapping_rule.update({'type': 'Slice', 'infer': caffe_slice_infer}) return mapping_rule
def extract(cls, node): proto_layer = node.pb param = proto_layer.psroi_pooling_param update_attrs = { 'spatial_scale': param.spatial_scale, 'output_dim': param.output_dim, 'group_size': param.group_size, } mapping_rule = merge_attrs(param, update_attrs) mapping_rule.update(layout_attrs()) # update the attributes of the node PSROIPoolingOp.update_node_stat(node, mapping_rule) return cls.enabled
def extract(cls, node): proto_layer = node.pb param = proto_layer.proposal_param update_attrs = { 'feat_stride': param.feat_stride, 'base_size': param.base_size, 'min_size': param.min_size, 'ratio': np.array(param.ratio), 'scale': np.array(param.scale), 'pre_nms_topn': param.pre_nms_topn, 'post_nms_topn': param.post_nms_topn, 'nms_thresh': param.nms_thresh } mapping_rule = merge_attrs(param, update_attrs) # update the attributes of the node ProposalOp.update_node_stat(node, mapping_rule) return cls.enabled
def extract(node): proto_layer = node.pb param = proto_layer.simpler_nms_param update_attrs = { 'cls_threshold': param.cls_threshold, 'max_num_proposals': param.max_num_proposals, 'iou_threshold': param.iou_threshold, 'min_bbox_size': param.min_bbox_size, 'feat_stride': param.feat_stride, 'pre_nms_topn': param.pre_nms_topn, 'post_nms_topn': param.post_nms_topn, 'scale': param.scale, } mapping_rule = merge_attrs(param, update_attrs) # update the attributes of the node Op.get_op_class_by_name(__class__.op).update_node_stat(node, mapping_rule) return __class__.enabled
def extract(node): proto_layer = node.pb param = proto_layer.prior_box_param variance = param.variance if len(variance) == 0: variance = [0.1] update_attrs = { 'aspect_ratio': np.array(param.aspect_ratio), 'min_size': np.array(param.min_size), 'max_size': np.array(param.max_size), 'flip': int(param.flip), 'clip': int(param.clip), 'variance': list(variance), 'img_size': param.img_size, 'img_h': param.img_h, 'img_w': param.img_w, 'step': param.step, 'step_h': param.step_h, 'step_w': param.step_w, 'offset': param.offset, } # these params can be omitted in caffe.proto and in param as consequence, # so check if it is set or set to default fields = [field[0].name for field in param.ListFields()] if 'density' in fields: update_attrs['density'] = np.array(param.density) if 'fixed_size' in fields: update_attrs['fixed_size'] = np.array(param.fixed_size) if 'fixed_ratio' in fields: update_attrs['fixed_ratio'] = np.array(param.fixed_ratio) mapping_rule = merge_attrs(param, update_attrs) mapping_rule.update(layout_attrs()) # update the attributes of the node Op.get_op_class_by_name(__class__.op).update_node_stat( node, mapping_rule) return __class__.enabled
def extract(node): proto_layer = node.pb param = proto_layer.interp_param update_attrs = { 'height': param.height, 'width': param.width, 'zoom_factor': param.zoom_factor, 'shrink_factor': param.shrink_factor, 'pad_beg': param.pad_beg, 'pad_end': param.pad_end } mapping_rule = merge_attrs(param, update_attrs) # in Caffe can be 2 inputs, shape should be got from shape of the second input mapping_rule['parse_2nd_input'] = 'shape' # update the attributes of the node Op.get_op_class_by_name(__class__.op).update_node_stat( node, mapping_rule) return __class__.enabled
def extract(node): proto_layer = node.pb param = proto_layer.st_param update_attrs = { 'transform_type': param.transform_type, 'sampler_type': param.sampler_type, 'output_H': param.output_H, 'output_W': param.output_W, 'to_compute_dU': int(param.to_compute_dU), 'theta_1_1': param.theta_1_1, 'theta_1_2': param.theta_1_2, 'theta_1_3': param.theta_1_3, 'theta_2_1': param.theta_2_1, 'theta_2_2': param.theta_2_2, 'theta_2_3': param.theta_2_3 } mapping_rule = merge_attrs(param, update_attrs) # update the attributes of the node Op.get_op_class_by_name(__class__.op).update_node_stat(node, mapping_rule) return __class__.enabled
def extract(cls, node): proto_layer = node.pb param = proto_layer.st_param update_attrs = { 'transform_type': param.transform_type, 'sampler_type': param.sampler_type, 'output_H': param.output_H, 'output_W': param.output_W, 'to_compute_dU': int(param.to_compute_dU), 'theta_1_1': param.theta_1_1, 'theta_1_2': param.theta_1_2, 'theta_1_3': param.theta_1_3, 'theta_2_1': param.theta_2_1, 'theta_2_2': param.theta_2_2, 'theta_2_3': param.theta_2_3 } mapping_rule = merge_attrs(param, update_attrs) # update the attributes of the node SpatialTransformOp.update_node_stat(node, mapping_rule) return cls.enabled
def extract(node): pl = node.pb assert pl, 'Protobuf layer can not be empty' param = pl.detection_output_param # TODO rewrite params as complex structures if hasattr(param, 'nms_param'): nms_threshold = param.nms_param.nms_threshold eta = param.nms_param.eta if param.nms_param.top_k == 0: top_k = -1 else: top_k = param.nms_param.top_k code_type_values = [ "", "caffe.PriorBoxParameter.CORNER", "caffe.PriorBoxParameter.CENTER_SIZE", "caffe.PriorBoxParameter.CORNER_SIZE" ] code_type = code_type_values[1] if hasattr(param, 'code_type'): if param.code_type < 1 or param.code_type > 3: log.error("Incorrect value of code_type parameter") return code_type = code_type_values[param.code_type] visualize_threshold = param.visualize_threshold if param.visualize_threshold else 0.6 resize_mode_values = [ "", "caffe.ResizeParameter.WARP", "caffe.ResizeParameter.FIT_SMALL_SIZE", "caffe.ResizeParameter.FIT_LARGE_SIZE_AND_PAD" ] if param.save_output_param.resize_param.resize_mode < 1 or param.save_output_param.resize_param.resize_mode > 3: log.error("Incorrect value of resize_mode parameter") return resize_mode = resize_mode_values[param.save_output_param.resize_param.resize_mode] pad_mode_values = [ "", "caffe.ResizeParameter.CONSTANT", "caffe.ResizeParameter.MIRRORED", "caffe.ResizeParameter.REPEAT_NEAREST" ] if param.save_output_param.resize_param.pad_mode < 1 or param.save_output_param.resize_param.pad_mode > 3: log.error("Incorrect value of pad_mode parameter") else: pad_mode = pad_mode_values[param.save_output_param.resize_param.pad_mode] interp_mode_values = [ "", "caffe.ResizeParameter.LINEAR", "caffe.ResizeParameter.AREA", "caffe.ResizeParameter.NEAREST", "caffe.ResizeParameter.CUBIC", "caffe.ResizeParameter.LANCZOS4" ] interp_mode = "" for x in param.save_output_param.resize_param.interp_mode: if x < 1 or x > 5: log.error("Incorrect value of interp_mode parameter") return interp_mode += interp_mode_values[x] attrs = { 'num_classes': param.num_classes, 'share_location': int(param.share_location), 'background_label_id': param.background_label_id, 'code_type': code_type, 'variance_encoded_in_target': int(param.variance_encoded_in_target), 'keep_top_k': param.keep_top_k, 'confidence_threshold': param.confidence_threshold, 'visualize': param.visualize, 'visualize_threshold': visualize_threshold, 'save_file': param.save_file, # nms_param 'nms_threshold': nms_threshold, 'top_k': top_k, 'eta': eta, # save_output_param 'output_directory': param.save_output_param.output_directory, 'output_name_prefix': param.save_output_param.output_name_prefix, 'output_format': param.save_output_param.output_format, 'label_map_file': param.save_output_param.label_map_file, 'name_size_file': param.save_output_param.name_size_file, 'num_test_image': param.save_output_param.num_test_image, # save_output_param.resize_param 'prob': param.save_output_param.resize_param.prob, 'resize_mode': resize_mode, 'height': param.save_output_param.resize_param.height, 'width': param.save_output_param.resize_param.width, 'height_scale': param.save_output_param.resize_param.height_scale, 'width_scale': param.save_output_param.resize_param.width_scale, 'pad_mode': pad_mode, 'pad_value': ','.join(str(x) for x in param.save_output_param.resize_param.pad_value), 'interp_mode': interp_mode, } # these params can be omitted in caffe.proto and in param as consequence, # so check if it is set or set to default fields = [field[0].name for field in param.ListFields()] if 'input_width' in fields: attrs['input_width'] = param.input_width if 'input_height' in fields: attrs['input_height'] = param.input_height if 'normalized' in fields: attrs['normalized'] = int(param.normalized) mapping_rule = merge_attrs(param, attrs) # force setting infer function because it doesn't exist in proto so merge_attrs will not set it mapping_rule.update({'infer': multi_box_detection_infer}) # update the attributes of the node Op.get_op_class_by_name(__class__.op).update_node_stat(node, mapping_rule) return __class__.enabled