Python问题:AttributeError: ‘str‘ object has no attribute ‘decode‘

2023-05-16

具体报错情况:

AttributeError                            Traceback (most recent call last)
<ipython-input-29-7b65833fd81b> in <module>
      8 from keras.utils.data_utils import get_file
      9 from tensorflow.keras.preprocessing.sequence import pad_sequences
---> 10 from shakespeare_utils import *
     11 # import sys
     12 # import io

D:\jupyter\5.1\shakespeare_utils.py in <module>
    131 x, y = vectorization(X, Y, n_x = len(chars), char_indices = char_indices)
    132 print("Loading model...")
--> 133 model = load_model('models/model_shakespeare_kiank_350_epoch.h5')
    134 
    135 

D:\Anaconda3\lib\site-packages\keras\engine\saving.py in load_wrapper(*args, **kwargs)
    456                 os.remove(tmp_filepath)
    457             return res
--> 458         return load_function(*args, **kwargs)
    459 
    460     return load_wrapper

D:\Anaconda3\lib\site-packages\keras\engine\saving.py in load_model(filepath, custom_objects, compile)
    548     if H5Dict.is_supported_type(filepath):
    549         with H5Dict(filepath, mode='r') as h5dict:
--> 550             model = _deserialize_model(h5dict, custom_objects, compile)
    551     elif hasattr(filepath, 'write') and callable(filepath.write):
    552         def load_function(h5file):

D:\Anaconda3\lib\site-packages\keras\engine\saving.py in _deserialize_model(h5dict, custom_objects, compile)
    245 
    246     if 'keras_version' in model_weights_group:
--> 247         original_keras_version = model_weights_group['keras_version'].decode('utf8')
    248     else:
    249         original_keras_version = '1'

AttributeError: 'str' object has no attribute 'decode'

 keras与h5py版本不兼容。
查看h5py的版本,未安装,自动安装后

pip install h5py==2.10.0

在2.10版本中,字符串的存储是经过编码的,而在3.0.0的版本中,则不会检查是否经过编码。所以才会出现最初的AttributeError: ‘str’ object has no attribute ‘decode’。

发现h5dict与h5py不兼容

卸载h5dict

 pip uninstall h5dict

安装

pip install h5dict==0.2.0 

运行一下 继续报错了

AttributeError: 'bytes' object has no attribute 'encode'

 但报错文档未出现encode(“utf-8”)

重启Jupyter notebook,重新打开即可

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Python问题:AttributeError: ‘str‘ object has no attribute ‘decode‘ 的相关文章

随机推荐

  • spring管理事务控制的问题

    在使用ssm框架开发项目时 xff0c 事务控制交由spring来管理 xff0c 然而在查看日志时发现一个问题 xff1a org mybatis spring SqlSessionUtils closeSqlSession SqlSes
  • 关于 Debian 系统

    Debian是什么 xff1f Debian 计划是一个致力于创建一个自由操作系统的合作组织 我们所创建的这个操作系统名为Debian 操作系统是使计算机运行的基本程序和工具的集合 xff0c 其中最主要的部分称为内核 xff08 kern
  • btrfs的子卷与快照功能--Linux下备份系统

    关于Btrfs 什么是Btrfs 以及它的性能 可以在许多地方查阅得到 这里要提到的是 Btrfs文件系统本身就是由子卷 Subvolumes 构成的 它的top level是由B tree结构的含有目录 文件和子卷等东西构成的子卷 而在t
  • c# 通过dotPeek调试.net源码

    1 安装dotPeek 2 设置dotPeek xff0c 开启pdb服务 3 设置VS xff0c 添加服务来源 取消仅我的代码 4 测试代码 xff0c 在Console WriteLine 打断点 xff0c 并按F11进入 注意 x
  • 超棒的离线文档阅读器:Zeal

    前言 xff1a 大家写代码的时候总会有些方法或者属性不太清楚 xff0c 这时候我们就会打开浏览器 xff0c 然后找官方api或者直接搜索引擎找对应问题 xff0c 无疑花费了大量的时间 所以 xff0c 你需要一个桌面应用Zeal x
  • UITabBarController标签控制器相关设置

    1 根据下标索引以及控制器索引显示需要显示的控制器 self selectedIndex 61 sender tag 100 self selectedViewController 61 VC 2 设置标签控制器下面的文字 这里是设置系统自
  • Node App: Note命令行应用程序

    此程序需安装npm 第三方库yargs 解析命令行参数 xff0c chalk 输出特定样式的文本 安装版本如下 xff1a chalk 4 1 1 yargs 17 0 1 Note 应用程序支持 4个命令 xff1a add 添加一个n
  • 怎么样用批处理来创建一个txt文件

    怎么样用批处理来创建一个txt文件 cd gt test txt cd 表示切换到当前目录 xff0c 这个命令没有任何作用 gt 是重定向符 xff0c 将当前输出重定向到文件 这个命令创建一个名为test txt的空文件
  • STM32F103寄存器方式点亮LED流水灯

    一 设计思路 本实验使用GPIOB GPIOC GPIOD这3个端口控制LED灯 GPIO 是通用输入输出端口的简称 xff0c 简单来说就是 STM32 可控制的引脚 xff0c STM32 芯片 的 GPIO 引脚与外部设备连接起来 x
  • 一步步CEF(2)之编译ceflicent

    一步步CEF xff08 1 xff09 之编译libcef dll wrapper lib已经提供了c 43 43 的静态库 xff0c 这次要将cefclient编译出来 这里要说明一下 xff0c 如果仅仅将cefclient编译的话
  • Java查找最长字符匹配子串

    1 比较两个字符串 xff0c 短的那一个先判断是否包含在长的字符串中 2 如果不在 xff0c 短的字符串子串长度 1 xff0c 从前往后移判断是否包含 xff0c 不包含继续此操作 public class getMaxStringT
  • Python,Anaconda环境安装配置

    文章目录 Python安装pip包管理 Anaconda安装conda包管理和环境管理Python3与Python2共存 xff08 Anconda3与Anaconda2共存 xff09 Jupyter notebook配置Jupyter
  • SVN提示E230001、E170013解决方案

    解决办法 1 Windows电脑打开cmd命令行 xff0c Mac电脑打开终端 2 输入如下命令 svn ls https 127 0 0 1 8888 svn XXXXXXXX 这里是项目的svn地址 他会提示你输入信息 xff0c 这
  • 记一次Nginx启动失败解决过程(环境:linux Ubuntu 16.04 64bit , ECS for Aliyun)

    背景 今天装了个jpress想弄个博客 xff0c 然后关了Nginx和uwsgi xff0c 启动了tomcat 使用80端口 xff0c 后来直接shutdown sh关闭tomcat后 xff0c 再次启动Nginx报了个错误 Job
  • Windows安装Qt在选择界面卡死解决方案

    Windows安装Qt在选择界面卡死解决方案 很简单的操作 xff1a 就是安装了有道词典 xff0c 退出有道词典 xff0c 再安装Qt 哈哈哈 xff0c 是不是很简单 xff0c 我也是摸索了半天才知道 xff0c 网上说的各种卸载
  • Linux之cmake3.6安装

    1 官网下载cmake 3 6 3 tar gz https cmake org files v3 6 cmake 3 6 3 tar gz 2 解压文件tar xvf cmake 3 6 3 tar gz xff0c 并修改文件权限chm
  • mysql 分组获取最新一条记录

    1 需求 按用户名分组 xff0c 获取最新插入的一条记录 2 模拟数据 span class token comment span span class token comment Table structure for user spa
  • 电脑连接树莓派出现问题--(putty,VNC,MobaXterm和远程桌面连接)

    以下解决方法与问题是基于我之前给树莓派写的一个开机自启动python脚本导致的问题所提出的 如果你从来没有给树莓派写过脚本 xff0c 那我的这篇博客对现在的你来说没有帮助 xff0c 不用浪费时间了 今天在用PC的Putty ssh方式连
  • STM32+ESP-07S+MQTT服务器实现数据上传和接收

    参考文章 xff1a https blog csdn net weixin 46144773 article details 128793578 https docs ai thinker com esp8266 sdk esp32下载工具
  • Python问题:AttributeError: ‘str‘ object has no attribute ‘decode‘

    具体报错情况 xff1a AttributeError Traceback most recent call last lt ipython input 29 7b65833fd81b gt in lt module gt 8 from k