如何给网站做排名,网页版传奇单职业,2018年期刊网站建设调查,网站的版面设计毕设学习笔记整理说明Python和Pycharm使用方面因网络问题导致pycharm安装第三方库失败的解决办法将python程序打包为exe程序pyinstallerpy2exepycharm取消缩进Python函数方面python中 if __name__ __main__: 的作用与意义cv2.resize的用法只读取图像的单通道数值最值索引图像增…
毕设学习笔记整理说明Python和Pycharm使用方面因网络问题导致pycharm安装第三方库失败的解决办法将python程序打包为exe程序pyinstallerpy2exepycharm取消缩进Python函数方面python中 if __name__ __main__: 的作用与意义cv2.resize的用法只读取图像的单通道数值最值索引图像增强数据增广的几种方法matlab中的一些函数numel()tictry/catch语句rand,randn,randi函数conv与convn的区别bsxfun()函数gzerosfloor()max()函数B ceil(A)调用GPU初始化数据将数据拷贝到GPU把GPU上的数据回传给CPU-——-使用gather函数对比CPU和GPU两种方式哪种快保存指定变量到.mat文件说明
毕设学习笔记整理涉及python和matlab,部分资料已上传有其他需要可以私信我。
Python和Pycharm使用方面
因网络问题导致pycharm安装第三方库失败的解决办法
在终端中使用pip安装选用国内的资源链接。 比如安装lxml库和requests库 输入
pip install -i https://pypi.douban.com/simple lxmlpip install -i https://pypi.douban.com/simple requests注其他库未尝试以上两个亲测速度飞快
将python程序打包为exe程序
pyinstaller
1、安装pyinstaller 2、输入命令
pyinstaller -F **\**\**.py如图里标黄所示-F 后面内容为你想打包的python文件。 3、查找自己打包的exe文件需要在dist文件夹下查找。 参考
py2exe
py2exe 似乎只能支持 python3.3 和 pyhton3.4 参考
pycharm取消缩进
pycharm编辑器的缩进和取消缩进快捷键 整体缩进 tab 整体取消缩进 tabshift
Python函数方面
python中 if name ‘main’: 的作用与意义
作用是以下程序只运行在主程序中即当该程序作为子程序import到其他程序中时以下程序不运行。
cv2.resize的用法
img_new cv2.resize(img, crop_size, interpolationcv2.INTER_CUBIC)
# CV_INTER_NN - 最近邻插值,
# CV_INTER_LINEAR - 双线性插值 (缺省使用)
# CV_INTER_AREA - 使用象素关系重采样。当图像缩小时候该方法可以避免波纹出现。当图像放大时类似于 CV_INTER_NN 方法..
# CV_INTER_CUBIC - 立方插值. 保留图像边缘与对比度。注不能存在中文路径此处错误大多为文件路径造成。
只读取图像的单通道
法1PIL
from PIL import Image
pil_im Image.open(empire.jpg).convert(L) # 转为灰度图像法2cv2
import cv2
img cv2.imread(jpg_name, cv2.IMREAD_GRAYSCALE)数值最值索引
max()函数有一个应用很巧妙的参数key在这里定义为operator.itemgetter(1)表示对enumerate(x)每个元素的第一维做比较从0维开始然后返回第一维值最大的元素即包含索引和数值。
x [3, 2.2, 7.4, 6, 4]
min_index, min_number min(enumerate(x), keyoperator.itemgetter(1))
# min_index1, min_number 2.2max_index, max_number max(enumerate(x), keyoperator.itemgetter(1))
# max_index2, max_number 7.4参考
图像增强数据增广的几种方法
考虑到本课题图像的特殊性不能进行几何变换因此这里只用了几种色彩变换的方法。
from PIL import Image, ImageEnhance, ImageOps, ImageFile
import matplotlib.pyplot as plt
jpg_name PVC_module_remove_1.jpg
pil_im Image.open(jpg_name).convert(L) # 打开单通道转为灰度图像# # 调整图像的饱和度 Color
# random_factor np.random.randint(10, 31) / 10. # 随机因子
# image_enhance_1 ImageEnhance.Color(pil_im).enhance(random_factor) # 调整图像的饱和度# 调整图像的亮度 Brightness
random_factor_2 np.random.randint(10, 21) / 10. # 随机因子
image_enhance_2 ImageEnhance.Brightness(pil_im).enhance(random_factor_2) # 调整图像的亮度# 调整图像的对比度 Contrast
random_factor_3 np.random.randint(10, 21) / 10. # 随机因子
image_enhance_3 ImageEnhance.Contrast(pil_im).enhance(random_factor_3) # 调整图像对比度# 调整图像锐度 Sharpness
random_factor_4 np.random.randint(0, 31) / 10. # 随机因子
image_enhance_4 ImageEnhance.Sharpness(pil_im).enhance(random_factor_4) # 调整图像锐度# 调整图像亮度、对比度、锐度
random_factor_5_reg np.random.randint(10, 21) / 10. # 随机因子
image_enhance_5_reg ImageEnhance.Contrast(image_enhance_2).enhance(random_factor_5_reg) #
random_factor_5 np.random.randint(0, 31) / 10. # 随机因子
image_enhance_5 ImageEnhance.Sharpness(image_enhance_5_reg).enhance(random_factor_5) # 调整图像锐度# 是否有变化
# changes1 np.asarray(image_enhance_1) - np.asarray(pil_im)
changes2 np.asarray(image_enhance_2) - np.asarray(pil_im)
changes3 np.asarray(image_enhance_3) - np.asarray(pil_im)
changes4 np.asarray(image_enhance_4) - np.asarray(pil_im)# 添加高斯噪声
# 噪声扰动
image_enhance_6 add_gaussian_noise(pil_im, 30)# 显示
plt.figure(原图像)
plt.imshow(pil_im, cmapplt.cm.gray)
# plt.show()
# plt.figure(调整图像的饱和度)
# plt.imshow(image_enhance_1,cmapplt.cm.gray)
# plt.show()
plt.figure(调整图像的亮度)
plt.imshow(image_enhance_2, cmapplt.cm.gray)
# plt.show()
plt.figure(调整图像的对比度)
plt.imshow(image_enhance_3, cmapplt.cm.gray)
# plt.show()
plt.figure(调整图像的锐度)
plt.imshow(image_enhance_4, cmapplt.cm.gray)plt.figure(调整图像亮度、对比度、锐度)
plt.imshow(image_enhance_5, cmapplt.cm.gray)plt.figure(添加噪声扰动后的图像)
plt.imshow(image_enhance_6, cmapplt.cm.gray)
# plt.show()plt.figure(changes4)
plt.imshow(changes4, cmapplt.cm.gray)
plt.show()# 保存图像不留空白显示保存
plt.xticks([]), plt.yticks([]) # 隐藏x、y轴
plt.subplots_adjust(top1, bottom0, right1, left0, hspace0, wspace0)
plt.margins(0, 0)
plt.imshow(img2,cmapplt.cm.gray)
plt.show()伽马校正
def adjust_gamma(image):image_reg np.array(image)random_factor np.random.uniform(0.5, 1.5) # 随机因子img1 np.power(image_reg / float(np.max(image_reg)), random_factor)return img1
程序下载链接
matlab中的一些函数
numel()
获取数组结构体中的元素数量 例如num numel(cnn.layer);
tic
通常与toc连用计算程序运行时间。
try/catch语句
try的作用是让Matlab尝试执行一些语句, 执行过程中如果出错, 则执行catch部分的语句. 其语法:
try
尝试执行的语句块
catch
出错后执行的语句块
end例如
tryc gpuArray(rand(varargin{:}));
catchc rand(varargin{:});
endrand,randn,randi函数
1rand 生成均匀分布的伪随机数。分布在0~1之间 主要语法 rand(m,n)生成m行n列的均匀分布的伪随机数 rand(m,n,‘double’)生成指定精度的均匀分布的伪随机数参数还可以是’single’ rand(RandStream,m,n)利用指定的RandStream(我理解为随机种子)生成伪随机数
2randn 生成标准正态分布的伪随机数均值为0方差为1 主要语法和上面一样
3,randi 生成均匀分布的伪随机 整数 主要语法 randiiMax在开区间0iMax生成均匀分布的伪随机整数 randiiMaxmn在开区间0iMax生成mXn型随机矩阵 r randi([iMin,iMax],m,n)在开区间iMiniMax生成mXn型随机矩阵
conv与convn的区别
conv只适用于两个一维信号的卷积运算 convn适合多维卷积运算 例如20 * 20 * 100 * 20与2 * 2卷积运算10 * 10 * 100 * 20 %full : 就是普通意义下的卷积 % same: 就是 和卷积输入的长度一样 % valid : 就是 卷积反转对齐之后这里的对齐很特殊不能有填充0
bsxfun()函数
C bsxfunfunAB使由函数句柄fun指定的逐元素二进制操作适用于数组A和B并启用了单例扩展。 fun可以是以下内置功能之一
语法功能plusPlusminusMinus times .Array multiplyrdivideRight array divideldivideLeft array dividepowerArray powermaxBinary maximumminBinary minimumrenRemainder after divisionmodModulus after divisionatan2Four quadrant inverse tangenthypotSquare root of sum of squareseqEqualheNot equalltLess thanleLess than or equal toptGreater thangeGreater than or equal toandElement-wise logical ANDorElement-wise logical ORsorLogical exclusive OR
gzeros
return zeros array on GPU
floor()
floor函数朝负无穷大方向取整 y floor(x) 函数将x中元素取整值y为不大于本身的最大整数。对于复数分别对实部和虚部取整
max()函数
c max(A) 返回A中的最大元素 [C,I] max(data_array); 返回A中的最大元素赋值给C将A中的最大元素的位置赋值给I.
B ceil(A)
返回对于每一个A中元素不小于的值
调用GPU初始化数据将数据拷贝到GPU
N 6;
M magic(N);%在CPU生成数组
G gpuArray(M); %将数据从CPU拷贝到GPU或
A zeros(10, gpuArray);把GPU上的数据回传给CPU-——-使用gather函数
最后是如何把GPU上的数据回传给CPU: B gather (A); 其中A是GPU上的数据B是CPU上的数据。B的内容在回传之后等于A。
对比CPU和GPU两种方式哪种快
%%
clc
clear all% %% 首先以200*200的矩阵做加减乘除做比较
% t zeros(1,100);
% A rand(200,200);B rand(200,200);C rand(200,200);
% for i1:100
% tic;
% DAB;EA.*D;FB./(Eeps);
% t(i)toc;
% end;
% t_m mean(t);
% fprintf(CPU平均运行时间%4f\n,t_m);
% %%%%ans 2.4812e-04
%
% t1 gpuArray(zeros(1,100));
% A1 gpuArray(rand(200,200));
% B1 gpuArray(rand(200,200));
% C1 gpuArray(rand(200,200));
%
% for i1:100
% tic;
% D1A1B1;E1A1.*D1;F1B1./(E1eps);
% t1(i)toc;
% end;
% t1_m mean(t1);
% fprintf(GPU平均运行时间%4f\n,t1_m);
% fprintf(速度快了%4f倍\n,t_m / t1_m);
% %% 结果
% % CPU运行时间0.000290
% % GPU平均运行时间0.000429
% % 速度快了0.675780倍%% 然后将矩阵大小提高到2000*2000做实验t zeros(1,100);
A rand(2000,2000);B rand(2000,2000);C rand(2000,2000);
for i1:100tic;DAB;EA.*D;FB./(Eeps);t(i)toc;
end;
t_m mean(t);
fprintf(CPU平均运行时间%4f\n,t_m);t1 gpuArray(zeros(1,100));
A1 gpuArray(rand(2000,2000));
B1 gpuArray(rand(2000,2000));
C1 gpuArray(rand(2000,2000));for i1:100tic;D1A1B1;E1A1.*D1;F1B1./(E1eps);t1(i)toc;
end;
t1_m mean(t1);
fprintf(GPU平均运行时间%4f\n,t1_m);
fprintf(速度快了%4f倍\n,t_m / t1_m);
%% 结果
% CPU平均运行时间0.025320
% GPU平均运行时间0.000747
% 速度快了33.911511倍 垃圾笔记本太可怜了运算次数少CPU快次数多GPU快
保存指定变量到.mat文件
fileDir 文件路径/; % 保存文件的路径
savePath strcat(fileDir, num2str(1), _result.mat); % 拼接路径和文件名
% num2str(n) 在循环中可以生成1_result.mat, 2_result.mat....
% 拼接后的文件为 文件路径/1_result.mat
save(savePath, val1, val2); % 保存变量val1,val2到1_result.mat中