A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

本帖最后由 梦缠绕的时候 于 2018-7-26 09:35 编辑

TensorFlow代码

数据处理:

输入为(344,288)的图片,首先进行归一化处理,然后下采样再上采样,得到输入input_,



  • def preprocess(path, scale=3):



  •   """



  •   Preprocess single image file



  •     (1) Read original image as YCbCr format (and grayscale as default)



  •     (2) Normalize



  •     (3) Apply image file with bicubic interpolation







  •   Args:



  •     path: file path of desired file



  •     input_: image applied bicubic interpolation (low-resolution)



  •     label_: image with original resolution (high-resolution)



  •   """



  •   image = imread(path, is_grayscale=True)#(344,228)



  •   label_ = modcrop(image, scale)#(342,228)modcrop得到scale的整数倍







  •   # Must be normalized



  •   image = image / 255.



  •   label_ = label_ / 255.







  •   input_ = scipy.ndimage.interpolation.zoom(label_, (1./scale), prefilter=False)#(114,76)



  •   input_ = scipy.ndimage.interpolation.zoom(input_, (scale/1.), prefilter=False)#(342,228)



  •   return input_, label_


得到子图片



  • input_, label_ = preprocess(data[0], config.scale)







  •     if len(input_.shape) == 3:



  •       h, w, _ = input_.shape



  •     else:



  •       h, w = input_.shape#(342,228)







  •     # Numbers of sub-images in height and width of image are needed to compute merge operation.



  •     nx = ny = 0



  •     for x in range(0, h-config.image_size+1, config.stride):#(0,310,21)nx=15,ny=10



  •       nx += 1; ny = 0



  •       for y in range(0, w-config.image_size+1, config.stride):#(0,196,21)



  •         ny += 1



  •         sub_input = input_[x:x+config.image_size, y:y+config.image_size] # [33 x 33]



  •         sub_label = label_[x+int(padding):x+int(padding)+config.label_size, y+int(padding):y+int(padding)+config.label_size] # [21 x 21]







  •         sub_input = sub_input.reshape([config.image_size, config.image_size, 1])  #(33,33,1)



  •         sub_label = sub_label.reshape([config.label_size, config.label_size, 1])  #(21,21,1)







  •         sub_input_sequence.append(sub_input)



  •         sub_label_sequence.append(sub_label)







  •   """



  •   len(sub_input_sequence) : the number of sub_input (33 x 33 x ch) in one image



  •   (sub_input_sequence[0]).shape : (33, 33, 1)



  •   """



  •   # Make list to numpy array. With this transform



  •   arrdata = np.asarray(sub_input_sequence) # [?, 33, 33, 1]



  •   arrlabel = np.asarray(sub_label_sequence) # [?, 21, 21, 1]







  •   make_data(sess, arrdata, arrlabel)







  •   if not config.is_train:



  •     return nx, ny        #15,10



3 个回复

倒序浏览
回复 使用道具 举报
奈斯,很赞
回复 使用道具 举报
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马