• 【已解决】胎教级别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,到这就能在本机跑起来了,上图

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

  • 相关阅读:
    念一句咒语 AI 就帮我写一个应用,我人麻了...
    求解答 能想的都想了但是还是不对
    树莓派上,docker下安装rancher与k8s,docker版本对应关系
    JavaWeb-JavaWeb中的I/O(输入/输出)
    YOLO系列改进论文阅读
    Paddle build_cinn_pass_test源码阅读(fluid目录下)
    分享一个 asp.net core 多文件分块同时上传的组件
    C++设计模式:单例模式
    TiDB 工具功能概览
    奇技淫巧第7期
  • 原文地址:https://blog.csdn.net/BetrayFree/article/details/133217407