【已解决】胎教级别FontDetection在本机电脑指导跑通

问题描述

        今天在自己电脑跑YuzuMarker.FontDetection的时候出现了一些问题,包括且不限于ModuleNotFoundError: No module named 'yaml',ModuleNotFoundError: No module named 'fontTools',AttributeError: 'NoneType' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead,PytorchStreamReader failed reading zip archive: failed finding central,接下来说一下解决办法以及原因分析。

原因分析与解决办法

        ModuleNotFoundError: No module named 'yaml'

        yaml模块的pip工具包名称不是yaml,而是pyyaml,所以不是直接pip install yaml:

pip install pyyaml
        ModuleNotFoundError: No module named 'fontTools'

        这个很明显是缺少fontTools,直接:

pip install fontTools

        不过运行到这有一个问题,为什么呢?为什么会少这么多包呢?很简单,我肯定没把requirement里面的东西都提前下载好:

pip install -r requirements.txt
pip install -r requirements_generate_font_dataset.txt

        ok,安装完这些依赖,世界就变得安静了,没有报错。

        AttributeError: 'NoneType' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead.

        但是按照readme里面的操作,却在执行python demo.py的时候报错:AttributeError: 'NoneType' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead.

        按照报错内容是某个地方存在空值

        如果只是执行python demo.py就必须保证解析的参数都不为空值,但是很恐怖

        这个checkpoints竟然是NONE,所以需要传入一个pretrained-weight值,ok我这里用的是

python demo.py --checkpoint https://huggingface.co/gyrojeff/YuzuMarker.FontDetection/resolve/main/commit%3Dbc0f7fc-epoch%3D26-step%3D261954.ckpt

        这样执行会开始下载预训练权重到cache中,但是下载完成之后问题又来了

        诶,很常见的错误,但是为什么会有这个错误呢?冷静下来分析就是预训练权重和模型的参数是不匹配的,所以会报错:Unexpected key(s) in state_dict,一定要注意,这里是 Unexpected key(s),为什么这么提醒呢?来,在执行下面这条:

python demo.py --checkpoint https://huggingface.co/gyrojeff/YuzuMarker.FontDetection/resolve/main/name%3D4x-epoch%3D19-step%3D388080.ckpt --model resnet101

        当我们把model换成resnet101的时候

        注意关键,这个时候的报错变成了Missing key(s) in state_dict:通过这样的例证就更能证明模型和预训练权重的不匹配是真实存在的,经过探索,下面这条是完全可以跑通的

python demo.py --checkpoint https://huggingface.co/gyrojeff/YuzuMarker.FontDetection/resolve/main/commit%3Dbc0f7fc-epoch%3D26-step%3D261954.ckpt --model resnet50

        并且相对于huggingface上的demo,这个准确率会更高一些。

        PytorchStreamReader failed reading zip archive: failed finding central

        这个问题应该算的上常见:就是下载的权重文件损坏了。遇到:PytorchStreamReader failed reading zip archive: failed finding central 错误应该如何解决icon-default.png?t=N7T8https://blog.csdn.net/q7w8e9r4/article/details/132139904        这个链接里面有具体的解析,但是呢?说的太繁琐了,直接上操作:

python demo.py --checkpoint https://huggingface.co/gyrojeff/YuzuMarker.FontDetection/resolve/main/commit%3Dbc0f7fc-epoch%3D26-step%3D261954.ckpt --model resnet50

        执行这行代码基本就解决了,当然细心的同学可能也发现了,这部没啥区别吗?是有区别的,区别在于你需要自己去找到缓存的文件,删掉,然后在执行!既然损坏了,那留他有何用?

        OSError: Cannot find empty port in range: 7860-7860. You can specify a different port by setting the GRADIO_SERVER_PORT environment variable or passing the `server_port` parameter to `launch()`.

        相比之下,这个问题就会容易些,报错内容是找不到这个空余端口,也就是说没有这个端口,那怎么办呢?肯定是被其他进程用了呗(注意,这里说的是进程而非程序,二者的区别见这篇博客:进程与程序的区别_进程和程序的区别-CSDN博客)。言归正传,既然端口被其他人用了,那解决办法也就有了:

1、停掉其他的进程;

2、换用其他端口。

务必注意这一点,在其他的程序中可能也会用到。

完结撒花

        ok,到这就能在本机跑起来了,上图

         其实在这里面,作者有很多并没有明说,我也是摸索着来的,比如字库选择还有背景图片都没有明说,只给了个大概的范围,这个解压寻找的过程是让人很难受的,我用了三天才搞定了最基本的数据集,当然,这肯定和我本身的机器垃圾脱不了关系,所以各位,且行且珍惜。

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值