语义分割学习笔记(五)——DenseImageData 数据层

1 参数

message DenseImageDataParameter {
  // Specify the data source file.
  optional string source = 1;
  // Specify the batch size.
  optional uint32 batch_size = 2;
  // The rand_skip variable is for the data layer to skip a few data points
  // to avoid all asynchronous sgd clients to start at the same point. The skip
  // point would be set as rand_skip * rand(0,1). Note that rand_skip should not
  // be larger than the number of keys in the database.
  optional uint32 rand_skip = 3 [default = 0];
  // Whether or not ImageLayer should shuffle the list of files at every epoch.
  optional bool shuffle = 4 [default = false];
  // It will also resize images if new_height or new_width are not zero.
  optional uint32 new_height = 5 [default = 0];
  optional uint32 new_width = 6 [default = 0];
  // Label gets divided by this factor, to train the encoder architecture of ENet.
  optional uint32 label_divide_factor = 13 [default = 1];
  // Specify if the images are color or gray
  optional bool is_color = 7 [default = true];
  optional string mean_file = 8;
  optional string root_folder = 9 [default = ""];
  optional bool mirror = 10 [default = false];
  optional uint32 crop_width = 11 [default = 0];
  optional uint32 crop_height = 12 [default = 0];
}
参数:
  label_divide_factor对标签图采样比例,SegNet没有label_divide_factor参数,ENet版本caffe有该参数

2 label_divide_factor对应源码层次修改

 //直接设定读图大小
    cv::Mat cv_lab = ReadImageToCVMat(root_folder + lines_[lines_id_].second,
            new_height/label_divide_factor, new_width/label_divide_factor, false, true);
			
	//设定top[1]大小
	top[1]->Reshape(batch_size, 1, height/label_divide_factor, width/label_divide_factor);
    this->prefetch_label_.Reshape(batch_size, 1, height/label_divide_factor, width/label_divide_factor);
    this->transformed_label_.Reshape(1, 1, height/label_divide_factor, width/label_divide_factor);


3 ReadImageToCVMat 源码在io.hpp  io.cpp中实现:

	#ifdef USE_OPENCV
	cv::Mat ReadImageToCVMat(const string& filename,
		const int height, const int width, const bool is_color,
		const bool nearest_neighbour_interp) {
	  cv::Mat cv_img;
	  int cv_read_flag = (is_color ? CV_LOAD_IMAGE_COLOR :
		CV_LOAD_IMAGE_GRAYSCALE);
	  cv::Mat cv_img_origin = cv::imread(filename, cv_read_flag);
	  if (!cv_img_origin.data) {
		LOG(ERROR) << "Could not open or find file " << filename;
		return cv_img_origin;
	  }
	  if (height > 0 && width > 0) {
		int cv_interp_flag = nearest_neighbour_interp ? CV_INTER_NN :
														CV_INTER_LINEAR;
		cv::resize(cv_img_origin, cv_img, cv::Size(width, height), 0, 0,
			cv_interp_flag);
	  } else {
		cv_img = cv_img_origin;
	  }
	  return cv_img;
	}

	cv::Mat ReadImageToCVMat(const string& filename,
		const int height, const int width, const bool is_color) {
	  return ReadImageToCVMat(filename, height, width, is_color, false);
	}

	cv::Mat ReadImageToCVMat(const string& filename,
		const int height, const int width) {
	  return ReadImageToCVMat(filename, height, width, true);
	}

	cv::Mat ReadImageToCVMat(const string& filename,
		const bool is_color) {
	  return ReadImageToCVMat(filename, 0, 0, is_color);
	}

	cv::Mat ReadImageToCVMat(const string& filename) {
	  return ReadImageToCVMat(filename, 0, 0, true);
	}

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
你好!感谢提问。下面是有关 K210 学习笔记中串口通信的一些内容: 在 K210 开发板上,串口是一种常见的通信接口,用于将数据从一个设备传输到另一个设备。串口通信通常使用 UART (Universal Asynchronous Receiver/Transmitter) 协议。 要在 K210 上进行串口通信,首先需要使用两个引脚:一个用于接收数据(RX),一个用于发送数据(TX)。这些引脚可以通过 GPIO 端口与外部设备连接。 在 K210 的开发环境中,可以使用 MaixPy 或者 Kendryte Standalone SDK 进行串口编程。 在 MaixPy 中,可以使用 `uart` 模块来进行串口通信。例如,要初始化一个串口对象并设置波特率为 115200,可以使用以下代码: ```python from machine import UART uart = UART(UART.UART1, 115200) ``` 然后,可以使用 `uart.write()` 函数发送数据,使用 `uart.read()` 函数接收数据。例如: ```python uart.write("Hello, world!\n") data = uart.read(10) ``` 在 Kendryte Standalone SDK 中,可以使用 `uart.h` 头文件中的函数来进行串口通信。例如,要初始化一个串口对象并设置波特率为 115200,可以使用以下代码: ```c #include "uart.h" uart_init(UART_DEVICE_1, 115200); ``` 然后,可以使用 `uart_send_data()` 函数发送数据,使用 `uart_receive_data()` 函数接收数据。例如: ```c uart_send_data(UART_DEVICE_1, "Hello, world!\n", 14); char buffer[10]; uart_receive_data(UART_DEVICE_1, buffer, 10); ``` 以上是关于 K210 学习笔记中串口通信的简要介绍。如果你有更具体的问题,请随时提问!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值