Python基础
Python基础
一豆豆酱
这个作者很懒,什么都没留下…
展开
-
Python报错:module 'scipy' has no attribute 'xxx'
首先看使用的函数在不在这几个当中:以 interpolate 为例:scipy 将 interpolate 单独定义为一个小子库,所以调用的时候不能单独写import scipy而是要写成 import scipy.interpolate(图片中其他函数也如此)除此之外,scipy 将 imread 和 imsave 函数删除了,可以使用 imageio库中的 imread 和 ims...原创 2020-03-27 21:38:11 · 17575 阅读 · 4 评论 -
豆酱踩坑(一)—— python 图片保存与显示
编程小白最近跑程序,自己读数据集,大大小小的坑踩了无数。。汇总一下吧~~1. 使用save命令保存图片img.save(img_path, optimize=True) 注:是针对Image格式的图片,数组形式的图片不能这么保存 可以使用 img = Image.fromarray(img) 将数组类型转换成Image格式 0-1之间的浮点数是不能保存成Image格式的...原创 2020-03-11 13:39:19 · 3089 阅读 · 1 评论 -
python+opencv 将视频保存成 gif 动图
参考博客:https://blog.csdn.net/islinyoubiao/article/details/104978563直接放代码吧import cv2import imageiodef read_video(video_path): video_cap = cv2.VideoCapture(video_path) frame_count = 0 all_frames = [] while True: ret, frame = video_cap.read() if re原创 2020-07-31 09:40:07 · 4222 阅读 · 0 评论 -
二叉树非递归遍历——python
参考博客☞python实现二叉树和它的七种遍历前序遍历def pre_order(root): if not root: return None stack = [] node = root while node or stack: while node: print(node.val) stack.append(node) node = node.left node = stack.pop() node = node.right中序遍历def mid_o转载 2021-09-24 20:40:48 · 254 阅读 · 0 评论 -
pytorch 找到最小非零值及索引
pytorch 索引原创 2022-06-08 15:22:58 · 1129 阅读 · 0 评论 -
python判断二进制图片格式
Python判断图片格式原创 2022-11-14 17:19:48 · 713 阅读 · 1 评论 -
pytorch 计算网络参数
参考链接:https://blog.csdn.net/weixin_42926076/article/details/99678948 #网络参数数量 def get_parameter_number(net): total_num = sum(p.numel() for p in net.parameters()) trainable_num = sum(p.numel() for p in net.parameters() if p.requires_gr转载 2020-12-08 09:38:39 · 509 阅读 · 0 评论 -
豆酱踩坑(二)——pytorch Dataset中的__len__()函数
之前一直不知道__len__()函数的作用,直到昨天在加载数据集的时候发现数据被“吞了”。。。原来6360张图片,加载后就剩30多张了,用debug也没发现哪里有问题。随手一翻程序,发现__len__()函数写错了,原本应该是list的长度,不小心写成了list的地址。。def __len__(self): return len(self.image_list)所以__len__()的...原创 2020-03-11 17:19:04 · 7346 阅读 · 0 评论