代码:

#-*-coding:utf-8-*-
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
filepath = '/media/wzg16/DATA2/Datasets/data/test_data/cat.jpg'def distort_color(image,color_ordering=0):if color_ordering ==0:image = tf.image.random_brightness(image,max_delta=32./255.)image = tf.image.random_saturation(image,lower=0.5,upper=1.5)image = tf.image.random_hue(image,max_delta=0.2)image = tf.image.random_contrast(image,lower=0.5,upper=1.5)elif color_ordering ==1:image = tf.image.random_saturation(image, lower=0.5, upper=1.5)image = tf.image.random_brightness(image, max_delta=32. / 255.)image = tf.image.random_contrast(image, lower=0.5, upper=1.5)image = tf.image.random_hue(image, max_delta=0.2)elif color_ordering ==2:image = tf.image.random_hue(image, max_delta=0.2)image = tf.image.random_brightness(image, max_delta=32. / 255.)image = tf.image.random_saturation(image, lower=0.5, upper=1.5)image = tf.image.random_contrast(image, lower=0.5, upper=1.5)else:image = tf.image.random_contrast(image, lower=0.5, upper=1.5)image = tf.image.random_brightness(image, max_delta=32. / 255.)image = tf.image.random_saturation(image, lower=0.5, upper=1.5)image = tf.image.random_hue(image, max_delta=0.2)return tf.clip_by_value(image,0.0,1.0)def preprocess_for_train(image,height,width,bbox):if bbox is None:bbox = tf.constant([0.0,0.0,1.0,1.0],dtype = tf.float32,shape=[1,1,4])if image.dtype != tf.float32:image = tf.image.convert_image_dtype(image,tf.float32)bbox_begin,bbox_size,_ = tf.image.sample_distorted_bounding_box(tf.shape(image),bounding_boxes=bbox)distorted_image = tf.slice(image,bbox_begin,bbox_size)##adjust sizedistorted_image = tf.image.resize_images(distorted_image,[height,width],method=np.random.randint(4))## flip left rightdistorted_image = tf.image.random_flip_left_right(distorted_image)## adjust colordistorted_image = distort_color(distorted_image,color_ordering=np.random.randint(2))return distorted_imageimage_raw_data = tf.gfile.FastGFile(filepath,'r').read()with tf.Session() as sess:image_data = tf.image.decode_jpeg(image_raw_data)boxes = tf.constant([[[0.05,0.05,0.9,0.7],[0.35,0.47,0.5,0.56]]])for i in range(6):result = preprocess_for_train(image_data,299,299,boxes)plt.subplot(2,3,i+1)plt.imshow(result.eval())plt.show()

出错情况:(pycherm编译器)

错误修改:

文件读取命令:

image_raw_data = tf.gfile.FastGFile(filepath,'r').read()

修改成('r'-->'rb'):

 image_raw_data = tf.gfile.FastGFile(filepath,'rb').read()

调试错误:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte相关推荐

  1. 解决UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte问题

    此文首发于我的个人博客:解决UnicodeDecodeError 'utf-8' codec can't decode byte 0xff in position 0 invalid start by ...

  2. UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xff in position 0: invalid start byte ,mac

    从网上查了很多种方法*均对我的bug不是很奏效,可能因为我的.txt文件是.xls文件转的,且我要读取的文件只有6个,遂采取最brute的方法:把所有文件里的内容copy出来,放到新文件里即可. *方 ...

  3. pandas 读取csv : ‘utf-8‘ codec can‘t decode byte 0xff in position 0: invalid start byte

    问题描述 用python 读取csv文件时,报错utf-8' codec can't decode byte 0xff in position 0: invalid start byte 问题原因 打 ...

  4. [Solved] UnicodeDecodeError: ‘utf-8’ codec can’t decode byte 0xff in position 0: invalid start byte

    1. with open(path, 'rb') as f:contents = f.read()2. with open(path, encoding="utf8", error ...

  5. ‘UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xff in position 0: invalid start byte‘成功解决

    今天在用pandas进行读取时出现了bug 出现这种情况的原因是:文件的编码不是 UTF8 编码的,而pandas读取文件时固定采用 UTF8 解码.解决方法是改为对应的解码方式. 解决的方式有两种: ...

  6. UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xff in position 41: invalid start byte

    文章目录 一.遇到报错 二.错误分析与解决 一.遇到报错 笔者在进行代码复现的时候,在数据读取时遇到报错: UnicodeDecodeError: 'utf-8' codec can't decode ...

  7. python错误:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb5 in position 0: invalid start byte

    python错误:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb5 in position 0: invalid start byte解 ...

  8. UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0x80 in position 0: invalid start byte 错误解决

    UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte 错误解决 解决: ...

  9. UnicodeDecodeError: 'utf8' codec can't decode byte 0xb1 in position 0: invalid start byte

    在Python处理字符编码时出现如下错误: UnicodeDecodeError: 'utf8' codec can't decode byte 0xb1 in position 0: invalid ...

最新文章

  1. 手把手快速实现 Resnet 残差模型实战
  2. containerd — 容器引擎
  3. 04-图像的阈值操作
  4. Eclipse 安装插件报错:An error occurred while collecting items to be installed session context was...解决方法汇总
  5. 【pytorch 】torchvision.transforms.CenterCrop==>从图像中心裁剪图片
  6. spring mvc java 把多文件打包成zip,并下载
  7. 谈谈如何构建技术部门的知识库
  8. 饱和气压与温度的关系_高中物理讲义:固体液体与物态变化第3节《饱和汽与饱和汽压》...
  9. java反序列化的原理,java – 反序列化的工作原理?
  10. 装机软件备忘、分类介绍 评点
  11. DHZT_ROS_Developer_Guide 大华中天ROS风格指南
  12. 移动硬盘只显示盘符,不显示容量,也不能打开
  13. 遗传算法之:八皇后问题
  14. 还在找怎么修复老照片?火爆全网的老照片修复技术方法其实很简单
  15. 数据驱动「付费转化」的3个思路
  16. 查找list中重复数据
  17. Android开发手机通讯录
  18. idea intellij 教育版申请
  19. 加载TQ2440驱动-Hello World 模块
  20. 2021年塔式起重机司机考试题及塔式起重机司机免费试题

热门文章

  1. python爬取贴吧图片_Python爬取贴吧多页图片
  2. 液晶拼接处理器_创新维OLED拼接屏施工单位操作说明
  3. 参数调整 新部署rac_CDH5部署三部曲之三:问题总结
  4. mysql -e 导出_mysql 导出数据导入数据
  5. oracle安装后再建库,oracle-数据库的安装与建库
  6. java语言生日蛋糕代码_AcWing 168. 【Java】生日蛋糕
  7. c+const_如何在C ++中使用const? 初学者指南
  8. python调用c语言函数_从Python调用C函数
  9. [nsis]安装包界面乱码问题
  10. Java面试题:final和Object类常见的方法