171026 data preparation for cooling-bin
来源:互联网 发布:数据融合主要技术 编辑:程序博客网 时间:2024/06/06 06:35
# -*- coding: utf-8 -*-"""Created on Thu Oct 26 21:39:45 2017@author: brucelau"""#%%# data preparationimport matplotlib.pyplot as plt import numpy as npimport osfrom PIL import Image#%%# make folders for data preparationif not os.path.exists('data_preparation'): for i in range(4): os.makedirs('data_preparation\\Light'+str(i+1)+'\\Good') os.makedirs('data_preparation\\Light'+str(i+1)+'\\Bad') print('data_preparation and TRTE folders created.')else: print('data_preparation or TRTE folders have been created.')#%%# make folders for training and testing if not os.path.exists('TRTE'): os.makedirs('TRTE\\TRGood') os.makedirs('TRTE\\TRBad') os.makedirs('TRTE\\TEGood') os.makedirs('TRTE\\TEBad') print('TRTE folders created.')else: print('TRTE folders have been created.')#%%# get pictures pathgood_files = os.listdir('Good\\')good_files = ['Good\\' + i for i in good_files]bad_files = os.listdir('Bad\\')bad_files = ['Bad\\' + i for i in bad_files]#%%# crop and save picturesdef crop_save_pic(original_files=good_files,good_or_bad='Good\\'): index = 0 # crop name index if os.listdir('data_preparation\\Light1\\Good\\')==[]: for idx, item in enumerate(original_files): im = Image.open(original_files[idx]) box = (700,160,1750,860) region = im.crop(box) order = idx%4 region.save('data_preparation\\Light'+str(order+1)+'\\'+good_or_bad # save path +str(int((index-index%4)/4)+1)+'.png') # save name # if idx+1==8: # break index +=1 print(index) else: print('all pictures has been croped.')crop_save_pic(original_files=good_files,good_or_bad='Good\\')crop_save_pic(original_files=bad_files,good_or_bad='Bad\\')#%%# randomly select pictures as training or testing data with a fixed probability def sel_prob(x): val = ['True','False'] p_true = 0.88 return np.random.choice(val,p=[p_true,1-p_true])def sel_index(arr): all_index = np.arange(len(arr)) pro_value = np.array(np.array([sel_prob(i) for i in arr])) sel_index_1 = np.where(pro_value=='True') sel_index_2 = np.where(pro_value=='False') return all_index[sel_index_1], all_index[sel_index_2]good = np.arange(279)bad = np.arange(83)TRGood_index,TEGood_index = sel_index(good)TRBad_index, TEBad_index = sel_index(bad)#%%# save cropped pitures as training or testing datadef trans_cropped(cropped_path, trans_path): for i in cropped_path: name = i.split('\\')[-1] im = Image.open(i) im.save(trans_path+'\\'+name)TRTE_path = ['TRTE\\TRGood\\','TRTE\\TRBad\\','TRTE\\TEGood\\','TRTE\\TEBad\\']path_TRGood = ['data_preparation\\Light1\\Good\\'+str(i+1)+'.png' for i in TRGood_index]path_TRBad = ['data_preparation\\Light1\\Bad\\'+str(i+1)+'.png' for i in TRBad_index]path_TEGood = ['data_preparation\\Light1\\Good\\'+str(i+1)+'.png' for i in TEGood_index]path_TEBad = ['data_preparation\\Light1\\Bad\\'+str(i+1)+'.png' for i in TEBad_index]if os.listdir('TRTE\\TRGood\\')==[]: trans_cropped(path_TRGood,TRTE_path[0]) trans_cropped(path_TRBad,TRTE_path[1]) trans_cropped(path_TEGood,TRTE_path[2]) trans_cropped(path_TEBad,TRTE_path[3])else: print('all cropped pictures have been transfered!')
阅读全文
0 0
- 171026 data preparation for cooling-bin
- Library Data Preparation for ICC---1
- kaldi data preparation
- Preparation for OpenGL programming
- Preparation
- Problem Preparation for HTML to TXT
- Notes for studing Java - Development preparation
- ftp 150 Opening ASCII mode data connection for /bin/ls.
- The preparation for installing Oracle after installing OS
- Wafer cooling for a high current serial ion implantation system
- ftp错误150 Opening ASCII mode data connection for /bin/ls.
- Database Testing – Properties of a Good Test Data and Test Data Preparation Techniques
- IBM Certificate Roadmaphttp://www-306.ibm.com/software/data/education/cert/preparation.html
- Effective preparation
- webex preparation
- Problem Preparation
- Problem Preparation
- Problem Preparation
- 关于NRF24L01只能接收一次数据问题的解决办法
- 初学MFC应该搞懂对话框、控件、控件ID、消息等概念和他们的关系
- 1045. 快速排序(25)
- 为了分析WebRTC, 重学Windows开发
- Mac的磁盘操作命令
- 171026 data preparation for cooling-bin
- Mabits的PageHelper分页插件的使用和Jsp分页页面展示(带源码)
- 深度学习之数学基础(数值计算)
- spring异常java.lang.IllegalStateException
- 1046. 划拳(15)
- java.lang.OutOfMemoryError异常解决方法
- tensorflow(一):tf.contrib.seq2seq.GreedyEmbeddingHelper
- 51Nod-1621-花钱买车牌
- docker入门1 : 使用docker镜像