城俊BLOG
从此好好码代码。。
展开
-
最佳买卖股票时机,含冷冻期
其他的题解可能答案也是对的,但是省略了一些必要的说明,导致理解起来有gap。大致就是分情况讨论,然后使用动态规划。关键在于分情况讨论,要足够清楚!这个题目纠结了很久,看了很多题解思路,都有没解释清楚的地方。可能题目本身也有没说的特别清楚的地方。原创 2023-04-04 23:36:50 · 1285 阅读 · 0 评论 -
Python双向链表插入节点
【代码】Python双向链表插入节点。原创 2023-03-28 22:12:36 · 881 阅读 · 0 评论 -
Python语法糖
语法糖就是程序语言中提供[奇技淫巧]的一种手段和方式而已。通过这类方式编写出来的代码,即好看又好用,好似糖一般的语法。【不知不觉之中一直在用的,并没有特别注意!Python语法糖包含哪些?翻译 2023-03-13 21:34:11 · 462 阅读 · 0 评论 -
....,,,
题目地址:https://leetcode.cn/problems/combination-sum/翻译 2023-02-21 18:07:08 · 116 阅读 · 0 评论 -
python读取excel获取单元格超链接的原始网址
【代码】python读取excel获取单元格超链接的原始网址。翻译 2023-01-31 22:07:01 · 1266 阅读 · 1 评论 -
conda报错CondaHTTPError: HTTP None None for url <https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/ma
$ conda update condaFetching package metadata ...CondaHTTPError: HTTP None None for url <https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64/repodata.json>Elapsed: NoneAn HTTP error occurred when trying to retrieve this URL.HTTP er翻译 2022-05-05 20:49:33 · 3653 阅读 · 2 评论 -
cv2画多边形报错Overload resolution failed:> - Can‘t parse ‘pts‘. Sequence item with index 0 has a wrong t
报错:cv2.error: OpenCV(4.5.4-dev) :-1: error: (-5:Bad argument) in function 'polylines'> Overload resolution failed:> - Can't parse 'pts'. Sequence item with index 0 has a wrong type> - Can't parse 'pts'. Sequence item with index 0 has a wrong原创 2022-04-18 13:58:36 · 11774 阅读 · 0 评论 -
pytorch tensor按广播赋值 scatter_函数
>>> import torch>>> a = torch.tensor([[1,2,3],[4,5,6]])# 和a shape相同,但是用0填充>>> b = torch.full_like(a,0)>>> c = torch.tensor([[0,0,1],[1,0,1]])# 赋值索引>>> c[:,0]tensor([0, 1])# 广播机制赋值>>> b[range(n)原创 2022-03-15 09:42:09 · 2051 阅读 · 0 评论 -
linux ubuntu Killed
不明原因就杀死了没有任何其他报错就 Killed很可能是内存不够(比如 某个数据的load导致),换个大内存的机器再试一下吧,兄dei原创 2022-02-24 20:56:24 · 1179 阅读 · 0 评论 -
zipimport.ZipImportError: not a Zip file: ‘dist/iou3d-0.0.0-py3.6-linux-x86_64.egg‘
pass原创 2022-02-17 16:21:29 · 704 阅读 · 0 评论 -
yolo运行报错:IndexError: invalid index to scalar variable.
代码:yolo_layers = [layers[i[0] - 1] for i in network.getUnconnectedOutLayers()]报错:Traceback (most recent call last): File "Run.py", line 201, in <module> main() File "Run.py", line 137, in main detections = yolo.detect(yolo_img) File翻译 2022-01-13 17:21:30 · 2392 阅读 · 3 评论 -
mac m1 python vscode 远程调试代码(debug)配置,报错:Exception has occurred: ModuleNotFoundError
明明在命令行运行得好好的,TM就是找不到Exception has occurred: ModuleNotFoundErrorNo module named 'xxx'解决:原创 2021-12-25 18:16:50 · 2405 阅读 · 0 评论 -
python 读写json保存后中文部分出现乱码
文章目录报错现象:原因:解决:报错报错1:TypeError: can't concat str to bytes报错2:TypeError: sequence item 0: expected str instance, bytes found现象:读取的json中带有中文,做了一番处理之后另存为另一个json但是,保存出来的那个json文件中出现了 \u53a2\u5f0f\u8d27\u8f66 类似这种的乱码原因:没有做好编码转换,应该跟系统本身安装的编码字符集关系不大解原创 2021-12-22 23:06:34 · 1853 阅读 · 0 评论 -
source activate xxx报错 -bash: activate: No such file or directory
解决:# 不要搞错,不要用自己的虚拟环境env下的binexport PATH="~/miniconda3/bin:$PATH"source activate xxx原创 2021-12-08 22:27:22 · 7385 阅读 · 4 评论 -
python pip 安装apex报错:ERROR: Could not build wheels for cryptacular
发现直接装装不上:各种报错报错一:Failed to build cryptacularERROR: Could not build wheels for cryptacular which use PEP 517 and cannot be installed directly报错二:Failed to build cryptacularERROR: Could not build wheels for cryptacular, which is required to install p翻译 2021-11-10 21:23:09 · 14180 阅读 · 9 评论 -
TypeError: can‘t pickle module objects
报错:Traceback (most recent call last): File "/nfs/volume-902-6/xxxx/bad_test.py", line 66, in generate_pre_annot pickle.dump(proposals, f, protocol=None, fix_imports=True)TypeError: can't pickle module objects又一次阴沟里翻船,还好同事帮忙指出来的你这个pickle啊,它保存的东西需原创 2021-10-28 13:06:21 · 7895 阅读 · 3 评论 -
python opencv (cv2) 报错:TypeError: Scalar value for argument ‘color‘ is not numeric
你在用cv2的一些api画图的时候,可能会遇到这种报错:TypeError: Scalar value for argument ‘color‘ is not numeric原因是:你应该使用 (11,11,11) 这种颜色表示方法,就是三个整数的三元组。你好像在说我在说废话哥话还没说完,你可能觉得你就是这样干的然而还是报错了,没错,可能你print出来的跟实际用的不太一样,这种情况下,你需要把这三个数强制转成整数再试一下:a,b,c = int(a),int(b),int(c)cv2.circ原创 2021-09-30 13:47:59 · 1526 阅读 · 1 评论 -
pytorch import _ext报错ImportError: dynamic module does not define module export function(PyInit__ext)
编译后的DCN V2不能import不知道啥原因,最后也是莫名其妙的解决了参考:原创 2021-09-19 14:47:41 · 4339 阅读 · 2 评论 -
mac pro m1 python3.9 import cv2报错Reason: image not found
ssss原创 2021-09-18 14:29:14 · 925 阅读 · 1 评论 -
python3.7 pip 安装软件包报错:libiomp5.so: undefined symbol: ompt_start_tool
https://docs.anaconda.com/mkl-optimizations/index.html原创 2021-09-17 14:51:30 · 2004 阅读 · 0 评论 -
python cv2.cornerSubPix报错 OpenCV(4.5.3) :-1: error: (-5:Bad argument) in function ‘cornerSubPix‘
功能:根据图片和点的坐标去精修点的坐标代码:import cv2img = cv2.imread('xxx.jpg')subpix_criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.1)gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)pts = [[852, 698], [1122, 702]]corners = corners.reshape((len(pts),原创 2021-09-13 19:09:26 · 2284 阅读 · 0 评论 -
tensorflow2 按层加载模型参数 finetune
model = ArcfaceModel()# 加载原始权重文件ckpt_path = './checkpoints/arc_mbv2' # 该文件夹下存放了4个文件:checkpoint, e_8_b_40000.ckpt.data-00000-of-00002, e_8_b_40000.ckpt.data-00001-of-00002,e_8_b_40000.ckpt.indexckpt_path = tf.train.latest_checkpoint(ckpt_path)model.load原创 2021-08-25 11:42:51 · 629 阅读 · 0 评论 -
python json保存和读取
import jsondef json_to_dict(): json_dict = json.load(open('xxx.json', 'w')) pydict = {k:np.array(json_dict[k]) for k in json_dict.keys()} return pydict def dict_to_json(): pydict[k] = v with open('xxx.json', 'w') as f: js翻译 2021-08-24 22:17:32 · 429 阅读 · 0 评论 -
生成人脸图像样本对,测试precision, recall
def get_id_prob_imgs(id_path, prob_path): # 这里假设id图片只有一层目录,每个id一张照片; prob照片有两层目录,第一层子目录为id名称,子目录下面才是prob照片 id_imgs = [os.path.join(idpath,i) for i in os.listdir(id_path)] probsubpaths = [os.path.join(probpath,i) for i in os.listdir(probpath)]原创 2021-08-21 12:02:43 · 231 阅读 · 0 评论 -
模型转换:tensorflow2 模型转pb,pb转tflite
def img_to_batch(): img = cv2.imread('xxxx.jpg') img = cv2.resize(img, (112,112)).astype(np.float32) / 255. img_batch = np.expand_dims(img,0)def tf2_to_pb(): # load tf2 model = AAA(xxx) ckpt_path = tf.train.latest_checkpoint('./xx原创 2021-08-13 09:57:45 · 1382 阅读 · 2 评论 -
cv2.imshow报错 window.cpp:1274: error: (-2:Unspecified error) The function is not implemented.
Traceback (most recent call last):File “/home/data/PJS/test_bed/img_show.py”, line 18, in cv2.imshow(‘img’, img)cv2.error: OpenCV(4.5.3) /tmp/pip-req-build-9gwtlx3c/opencv/modules/highgui/src/window.cpp:1274: error: (-2:Unspecified error) The function i原创 2021-08-08 11:14:03 · 5147 阅读 · 2 评论 -
图片文件拷贝、目录拷贝
def copy_imgs(src, dstPath, newFileName=False): import shutil import sys try: # if dstPath is path and newFileName=False, then copy without rename # if dstPath is new file name, then copy and rename if not newFileName:原创 2021-07-27 16:46:45 · 246 阅读 · 0 评论 -
【汇总】多进程、多线程、并行、并发相关
文章目录简单示例按键检测、转发报错和解决进程间通信简单示例linux ubuntu Python 多进程执行程序按键检测、转发通过SSH协议给python多进程转发按键python multiprocessing多进程按键检测,优雅地终止多进程(signal信号量和pynput等多种方法)报错和解决python多进程 multiprocessing.pipe 管道没有数据接收端会卡死,无提示,无报错!!!python多进程管道 multiprocessing.Pipe OSErro原创 2021-07-24 16:34:58 · 146 阅读 · 0 评论 -
Python txt 读取文本文件ReadTxt,获取所有图片文件列表
读取txt文件# read txt file content to listdef ReadTxt_to_list(rootdir): lines = [] with open(rootdir, 'r') as file_to_read: while True: line = file_to_read.readline() if not line: break li.原创 2021-07-21 10:38:49 · 319 阅读 · 0 评论 -
kmeans聚类 之再也不要写错了
# kmeans 聚类import numpy as npdef kmeans(data,num,max_iter,tol): # step1 centers = {} for i in range(num): centers[i] = data[i] # step2 for i in range(max_iter): clf = {} for feature in data:原创 2021-07-07 22:01:29 · 353 阅读 · 1 评论 -
linux ubuntu Python 多进程并行执行程序
from functools import partial pt = partial(add_mask, args) # multi process from multiprocessing import Process import multiprocessing as mp ctx = mp.get_context('spawn') q = ctx.Queue() split_list = r'/home/xxx/data/CASI...原创 2021-07-05 16:46:12 · 1418 阅读 · 5 评论 -
数据增强
pass原创 2021-06-22 19:40:38 · 220 阅读 · 0 评论 -
mxnet根据相似度进行人脸样本对图片清理
背景:每个ID有ID图片和prob图片做法:加载模型,提取特征,计算id和prob的平均相似度,排序,保存import numpy as npimport osimport mxnet as mxfrom menpo.visualize import print_progressfrom collections import namedtupleBatch = namedtuple('Batch', ['data'])def constructmodel(prefix, ctx, epo原创 2021-06-21 17:22:49 · 251 阅读 · 2 评论 -
Python 图片resize 不改变宽高比,加黑边,图片无损旋转
# 编写适用于lfwa两级目录的图片文件列表提取def get_imgs(imgDir): subdirs = os.listdir(imgDir) subdirs = [os.path.join(imgDir, i) for i in subdirs] imgs = [] for subdir in subdirs: imgss = os.listdir(subdir) imgs.extend([os.path.join(subdir, i翻译 2021-06-18 09:34:39 · 2730 阅读 · 1 评论 -
python字符串:从左往右找、从右往左找,从右向左匹配替换
>>> 'XXX'.join('abcabcabcabc'.rsplit('abc', 1))'abcabcabcXXX'翻译 2021-06-15 12:41:26 · 2191 阅读 · 0 评论 -
图片输入数据检查: nan inf和不存在
import osimport cv2import numpy as npfrom tqdm import tqdm# read txt file content to listdef ReadTxt_to_list(rootdir): lines = [] with open(rootdir, 'r') as file_to_read: while True: line = file_to_read.readline()原创 2021-06-11 14:28:55 · 272 阅读 · 1 评论 -
Win10 Python IOError: [Errno 2] No such file or directory
报错:Traceback (most recent call last): File "C:/projects/0Fea/plot_test/plot_loss.py", line 23, in <module> lines = ReadTxtName(txt) File "C:/projects/0Fea/plot_test/plot_loss.py", line 11, in ReadTxtName with open(rootdir, 'r', ) as file原创 2021-05-25 09:47:35 · 626 阅读 · 0 评论 -
pytorch固定随机种子,训练稳定复现
固定python随机数rng = numpy.random.RandomState(23355)rng.uniform(0,1,(2,3))rng = numpy.random.RandomState(23355)rng.uniform(0,1,(2,3))原创 2021-04-28 17:14:20 · 3971 阅读 · 0 评论 -
Python多个等于号的表达式 a=b=c=d...=X
左边不管有多少个变量之间用等于号连接,仅仅是为了声明,最后一个等于号左边的所有变量都等于最右边的那个变量。翻译 2021-04-27 23:20:06 · 3383 阅读 · 0 评论 -
pycharm激活错误提示:JetBrains Account connection error: java.security.Signatur...256 but was expecting 512
报错:JetBrains Account connection error: java.security.SignatureException: Signature length not correct: got 256 but was expecting 512解决:在help - edit vm options中加一行配置:-Djava.net.preferIPv4Stack=true然后重启,重新registerhttps://blog.youkuaiyun.com/getture/article/det翻译 2021-04-15 10:51:45 · 901 阅读 · 0 评论