Python技巧
Python技巧
这就是算法
Talk is Cheap,Show me the code.
展开
-
anaconda 安装 tensorflow2.0
目前anaconda支持安装gpu版本的tensorflow安装,只需在自己的虚拟环境中输入conda install -c anaconda tensorflow-gpu原创 2020-11-05 14:52:50 · 512 阅读 · 0 评论 -
panda 基本操作
读取excel文件df = pd.read_excel('data.xlsx', sheet_name='数据-玉米')DataFrame根据索引 切片操作df = df.iloc[0:-1 ,0:-3]获取列名col_name = df.columns.values.tolist()获取根据列名,获取某一列,并将浮点型转换成int类型county_id = df.loc[:, col_name[0]].astype('int')把空缺值用0.00来填充prod原创 2020-12-23 10:56:01 · 437 阅读 · 0 评论 -
This sheet is too large
解决方法:df.to_excel("xxx.xlsx",index=False)改成df.to_csv('xxx.csv', index=False)原创 2021-01-10 19:38:01 · 3497 阅读 · 3 评论 -
解决pycharm中相对引用得问题
使用这个方法得前提是,我们需要保证路径是正确得,这个时候只需要按照下图操作点一下即可原创 2020-09-11 20:19:35 · 933 阅读 · 0 评论 -
对numpy 矩阵进行通道间求均值
给定一个3x2x2得矩阵,得到一个2x2的矩阵,其中对应元素是通道间的均值import numpy as npa = np.array([ [[1, 2], [3, 4]], [[5,6], [7,8]], [[1, 2], [3, 4]] ])print(a.shape) # (3, 2, 2)pr原创 2020-09-10 10:10:32 · 1225 阅读 · 0 评论 -
ImportError: numpy.core.multiarray failed to import遇见此问题的解决方案
总结一下自己在安装pytorch的时候 出现这个问题的原因先说一下自己的情况:anaconda 创建虚拟环境 pytorch2.使用官网的方法 conda install pytorch torchvision cudatoolkit=10.2 -c pytorch 来进行安装出现 ImportError: numpy.core.multiarray failed to import 这样的问题解决方案出现这个原因是numpy的版本过高,在使用官网的命令的时候,自动下载了n原创 2020-08-12 12:00:00 · 5023 阅读 · 0 评论 -
python 错误 ImportError:attempted relative import with no known parent package
https://blog.csdn.net/weixin_41699811/article/details/84965328使用上面博主的方法可以很好的解决原创 2020-06-27 14:43:42 · 1274 阅读 · 0 评论 -
map 没有len函数
错误:TypeError:object of type ‘map’ has no len()python 3 中的map没有len功能了解决方案:x = [[1, 'a'], [2, 'b'], [3, 'c']]len(map(lambda a: a[0], x))讲map强制转换成list 或者 tuple , 然后再求lenlen(list(map(lambda a: a[0], x)))使用列表推导,不使用mapmy_list = [a[0] for a in x]l原创 2020-06-22 21:52:02 · 509 阅读 · 0 评论 -
在安装tensorflow时 No metadata
原创 2019-04-13 15:58:21 · 1541 阅读 · 0 评论 -
在anaconda中的虚拟环境中安装tensorflow
pip install tensorflow-gpu -i https://pypi.doubanio.com/simple/原创 2019-04-13 08:22:04 · 490 阅读 · 0 评论 -
jupyter notebook 中的自动补全功能
在代码顶部添加%config IPCompleter.greedy=Trueshift+回车运行,对于接下来运行过的内容都会被列入自动提示中。原创 2019-01-07 14:32:04 · 1669 阅读 · 0 评论 -
python处理视频的几个操作
参数介绍:两组图片序列帧存放在source中,命名格式为 real_1.png、real_2.png、.......... fake_1.png、fake_2.png、...........将合成好的视频name(final.avi),保存在file('./results')中。 size为name(final.avi)的大小,注意格式为(width,height) size一定要和图片的大小对应好,否则final.avi无法播放import osimpo...原创 2021-03-11 14:49:46 · 3538 阅读 · 0 评论 -
The encoder ‘acc‘ is experimental codecs are not enabled ,add ‘-strict -2‘ if you want to use it.
使用如下命令出现错误:ffmpeg -i crop2.mp4 -ss 0.0 -t 9.0 -filter:v "crop=740:740:606:115, scale=256:256" crop.mp4实际上,在命令行中添加 -strict -2 是不够的。 添加 -strict -2 的位置非常重要,但是不幸的是,错误消息中没有对此进行解释。 它应该在最后一个参数之前,即,如下所示:ffmpeg -i crop2.mp4 -strict -2 crop.mp4...原创 2021-03-23 10:56:35 · 1316 阅读 · 0 评论 -
Python获取路径中最后的文件名,路径
path.split('\')[-1]os.path.basename(path)原创 2021-03-23 13:37:43 · 9383 阅读 · 1 评论 -
Could not fetch URL https://pypi.org/simple/icecream/: There was a problem confirming the ssl......
我在使用pip install icecream安装python库icecream时出现了这个问题:解决方法:使用如下命令:pip install package_name -i http://pypi.douban.com/simple --trusted-host pypi.douban.compip install icecream -i http://pypi.douban.com/simple --trusted-host pypi.douban.com可替换用的镜像源1)http原创 2021-04-04 17:10:10 · 189 阅读 · 0 评论 -
意外发现一个好用的Python debug工具icecream
github 链接Installation您是否曾经使用过print()或log()来调试代码?你可以使用ic()来进行调试pip install icecream带参数的ic()会输出变量的值以及其他辅助信息如果使用print(foo(123))进行调试则只输出456不带参数的ic()会检查自身并打印调用文件名,行号和父函数。from icecream import icdef foo(): ic() first() if expression:原创 2021-04-04 19:19:28 · 354 阅读 · 1 评论 -
使用SCP命令上传cuda安装包出现Permission denied问题
参考链接原创 2021-04-07 16:48:51 · 589 阅读 · 0 评论 -
使用Python将视频按照一定时间切割(比如:每10s进行裁切)
平台: Ubuntu 16.04函数库: ffmpeg、subprocess需求: 将path路径下的所有.mp4视频每delta_X(10s)进行裁切,并保存在save_path下,并裁切好的视频以id00001.mp4、id00002.mp4、id00003.mp4…命名保存注意: 每个视频不超过1小时、最后不足delta_X时间的会被舍弃。(根据需求自行修改)参考代码import subprocessimport ospath = '/home/dataset' # 待切割视频存储目原创 2021-04-08 19:42:49 · 6090 阅读 · 22 评论 -
ffmpeg:error while loading shared libraries: libopenh264.so.5(实测可用,记录于2021.4.29.17:00)
问题描述:在Ubuntu 10.04系统中,想用ffmpeg进行人脸的裁切,但是出现了标题的错误。我输入ffmpeg -version无法产生对应的版本号。经过Google之[https://stackoverflow.com/questions/62213783/ffmpeg-error-while-loading-shared-libraries-libopenh264-so-5],原来是too new。我是用的conda虚拟环境名称是houyw,如果下面出现了houyw就是我的虚拟名称。(1)原创 2021-04-29 16:01:10 · 5071 阅读 · 2 评论 -
Layout of the output array img is incompatible with cv::Mat
问题描述:Layout of the output array img is incompatible with cv::Mat (step[ndims-1] != elemsize or step[1] != elemsize*nchannels)原始代码:修改之后的代码:原创 2021-05-01 10:18:21 · 2159 阅读 · 1 评论 -
为RGB图像增加alpha通道(RGB -> RGBA)
1.使用opencvb_channel, g_channel, r_channel = cv2.split(img)alpha_channel = np.ones(b_channel.shape, dtype=b_channel.dtype) * 50 #creating a dummy alpha channel image.img_BGRA = cv2.merge((b_channel, g_channel, r_channel, alpha_channel))2.使用PILfr原创 2021-05-14 22:23:24 · 2663 阅读 · 1 评论 -
AttributeError: ‘str‘ object has no attribute ‘decode‘
在加载Keras训练好的模型时出现AttributeError: ‘str’ object has no attribute 'decode’错误解决方案:在Keras、Tensorflow版本正确的情况下,将conda环境中的h5py软件包降级即可解决此类问题。原创 2021-05-14 22:27:11 · 222 阅读 · 0 评论 -
python 图像旋转
import cv2import imutilsimage = cv2.imread(r"C:\Users\HP\OneDrive\Desktop\Penskull Education.png") rot = imutils.rotate(image, angle=45)cv2.imshow("Rotated", rot)cv2.waitKey(0)from PIL import Image img = Image.open(r"C:\Users\HP\OneDrive\Desk原创 2021-06-02 21:46:01 · 2058 阅读 · 4 评论 -
Unable to allocate 309. GiB for an array with shape (203769, 203769)
问题描述在Ubuntu20.04运行GCN时,使用pandas加载数据,出现如上错误解决方法首先使用如下命令查看是否是0cat /proc/sys/vm/overcommit_memory如果是0的话,使用如下命令,将其改为1(如果是1的话,我也不知道咋办)sudo -iecho 1 > /proc/sys/vm/overcommit_memory再次运行,错误消失...原创 2022-03-14 13:09:23 · 2403 阅读 · 0 评论 -
pytorch绘制网络结构图(以swin-unet为例)
原创 2021-11-22 16:13:38 · 2979 阅读 · 3 评论 -
Pytorch计算模型的参数量
比如说我计算TransUNet的参数量(计算之前需要安装thop库 pip install thop)from thop import profile, clever_formatflops, params = profile(net, inputs=(inputs,))macs, params = clever_format([flops, params], "%.3f") # 格式化输出print('flops':, macs) # 计算量print('params:',params) #原创 2021-03-31 00:40:40 · 1810 阅读 · 12 评论 -
ValueError: Expected more than 1 value per channel when training, got input size torch.Size
ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 512, 1, 1])在调试别的语义分割模型时,出现了这个错误。解决方案:我们需要做的就是更改batch的值,将1改成别的数字。...原创 2020-10-07 19:48:31 · 1751 阅读 · 0 评论 -
安装pydensecrf(100%成功:2020.12.13)
去网站下载与python版本对应的pydensecrf版本使用如下命令安装参考文章原创 2020-12-13 18:20:48 · 1913 阅读 · 1 评论 -
解决RuntimeError: cuDNN error: CUDNN_STATUS_EXECUTION_FAILED
方法1:在代码中加入torch.backends.cudnn.enabled = False原创 2021-05-04 14:39:27 · 3305 阅读 · 2 评论 -
one of the variables needed for gradient computation has been modified by an inplace operation
问题:one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [4, 2, 224, 224]], which is output 0 of SigmoidBackward, is at version 2; expected version 0 instead. Hint: enable anomaly detection原创 2021-06-16 07:41:13 · 433 阅读 · 0 评论 -
人脸旋转对齐(opencv-python)
知乎讲解github代码由于作者讲的太详细了,我就不鹦鹉学舌了,直接上讲解和代码的传送门原创 2021-06-16 11:23:32 · 1748 阅读 · 0 评论 -
cannot re-initialize CUDA in forked subprocess.To use CUDA with multiprocessing,you must use the ...
cannot re-initialize CUDA in forked subprocess.To use CUDA with multiprocessing,you must use the 'spawn' start method.我选择了向邪恶势力低头,将num_workers设置为0解决此问题原创 2021-06-29 15:39:35 · 2519 阅读 · 0 评论 -
anaconda虚拟环境自动生成 requirement.txt(2021.11.28完成)
Step1: 安装pipreqspip install pipreqsStep2: 生成requirement.txt pipreqs ./ --encoding=utf8安装requirement.txt中的类库pip install -r requirements.txt原创 2021-11-28 15:51:02 · 2317 阅读 · 0 评论 -
中文数字与阿拉伯数字转换(Python)
cn2an 是一个快速转化 中文数字 和 阿拉伯数字 的工具包相关链接cn2an工具包Github地址在线测试平台installgit clone https://github.com/Ailln/cn2an.gitcd cn2an && python setup.py install测试用例import cn2an# 在 cn2an 方法(默认)下,可以将句子中的中文数字转成阿拉伯数字output = cn2an.transform("小王捡了一百块钱")# 或者原创 2022-04-11 11:04:54 · 1877 阅读 · 1 评论