zoukankan      html  css  js  c++  java
  • Tensorflow问题

    TypeError: 'urban' has type str, but expected one of: bytes

    在前面添加"b"(例如,b'urban'),或者处理为variableName.encode("utf8")

    Variable count_var2 already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope?

    在开始的地方添加:

    tf.reset_default_graph()

    File "F:Program FilesPythonPython36lib andom.py", line 275, in shuffle

        x[i], x[j] = x[j], x[i]

    TypeError: 'range' object does not support item assignment

    后来定位原因是tfrecord是基于python2写的,里面range返回的list对象,但是再python3里面返回的是range对象。

    1 shuffled_index = range(len(filenames)) 
    2 random.seed(12345) 
    3 random.shuffle(list(shuffled_index))

    如此修改,问题解决

    UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 247: character maps to <undefined>

     with open(file=filename, mode="rb") as f: 

    将mode由"r"转变为"rb"

    https://blog.csdn.net/qq_41185868/article/details/82843781

    TypeError: 'RGB' has type str, but expected one of: bytes

     1     colorspace = b'RGB'
     2     channels = 3
     3     image_format = b'JPEG'
     4 
     5     example = tf.train.Example(features=tf.train.Features(feature={
     6         ...
     7         'image/colorspace': _bytes_feature(colorspace),
     8         ...
     9         'image/format': _bytes_feature(image_format),
    10        ...
    11     return example

    在colorspace以及image_format中添加了'b',问题解决。

    TypeError: 'water' has type str, but expected one of: bytes

    1 def _bytes_feature(value):
    2     """Wrapper for inserting bytes features into Example proto."""
    3     print("value值是: ", value)
    4     if(type(value) is not bytes):
    5       value = value.encode("utf8")
    6     return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value])) 
    def _bytes_feature(value):
        """Wrapper for inserting bytes features into Example proto."""
        print("value值是: ", value)
        if(type(value) is not bytes):

    注意bytes是python3中引入的一个类型;pyton2的时候后,string类型是可以当成byte来处理的,比如传输,但是到了python3时代,bytes和string是严格区分的;所有有了上面这段判断,如果不是bytes需要转换为byte(注意类型判断使用的是"is/ is not";

    ValueError: invalid literal for int() with base 10: 'lOOOOO'

    argument = "lOOOOOO" argument = int(argument) print("complete")

    后来发现那个圈其实是大写的"O"而不是"0"... ... 请问,这一条可以不写吗?后来想明白了原因,我是从PDF中直接粘出来的,PDF是一个根据图片生成的命令,会做一些莫名其妙的转换,发生了0转O的情况。

  • 相关阅读:
    在spring官网上下载历史版本的spring插件,springsource-tool-suite
    转载---VB DorpDownList控件 添加选项
    VB,将"秒"转成"时分秒"格式
    VB.NET 改变datatable数据类型
    转载--- C# 图片与base64编码 互相转换
    转载--- php5.6:Call to undefined function curl_init()的解决办法
    转载--- navicat12破解版(英文、中文)
    转载---mysql导出事件、存储过程、函数、库表
    C# 读取mysql blob字段(两种方式)
    转载---安装mysql5.7,遇到的问题
  • 原文地址:https://www.cnblogs.com/xiashiwendao/p/11180862.html
Copyright © 2011-2022 走看看