mysql修改表编码为ytf8_如何修复“TypeError:x和y必须具有相同的数据类型,got”tf.uint8型!= tf.float32型“当我试图以十为单位调整图像大小时...

本文分享了一次在TensorFlow中实现图像裁剪的具体实践,作者尝试构建一个图像数据集并将其裁剪为正方形,但遇到了类型转换错误。文中包含了解决此问题的详细步骤及代码示例。
部署运行你感兴趣的模型镜像

我试着建立一个图像管道,为Tensorflow构建一个图像数据集来裁剪图像,但是我无法裁剪图片。

我遵循了这个tutorial但是我想将文件裁剪成正方形,并且在不保留纵横比的情况下不调整其大小。

这是我的代码:#

import tensorflow as tf

#

img_raw = tf.io.read_file('./images/4c34476047bcbbfd10b1fd3342605659.jpeg/')

img_tensor = tf.image.decode_jpeg(img_raw, channels=3)

img_final = tf.image.crop_to_bounding_box(

img_tensor,

0,

0,

200,

200

)

img_final /= 255.0 # normalize to [0,1] range

当我像教程中那样使用简单的图像调整大小时,它会起作用:

^{pr2}$

以下是日志:img_final /= 255.0 # normalize to [0,1] range

File ".../.local/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 876, in binary_op_wrapper

return func(x, y, name=name)

File ".../.local/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 964, in _truediv_python3

(x_dtype, y_dtype))

TypeError: x and y must have the same dtype, got tf.uint8 != tf.float32

您可能感兴趣的与本文相关的镜像

TensorFlow-v2.15

TensorFlow-v2.15

TensorFlow

TensorFlow 是由Google Brain 团队开发的开源机器学习框架,广泛应用于深度学习研究和生产环境。 它提供了一个灵活的平台,用于构建和训练各种机器学习模型

import cx_Oracle import os def execute_index_statements(sql_file_path, error_file_path, db_username, db_password, db_dsn): """ 执行SQL文件中的CREATE INDEX语句,并将错误语句保存到新文件 :param sql_file_path: 包含CREATE INDEX语句的SQL文件路径 :param error_file_path: 错误SQL语句的输出文件路径 :param db_username: 数据库用户名 :param db_password: 数据库密码 :param db_dsn: 数据库DSN连接字符串 """ # 读取SQL文件并按分号分割语句 with open(sql_file_path, 'r') as sql_file: sql_content = sql_file.read() # 分割SQL语句,保留分号以便后续处理 raw_statements = [stmt.strip() + ";" for stmt in sql_content.split(';') if stmt.strip()] # 连接到Oracle数据库 try: connection = cx_Oracle.connect(user=db_username, password=db_password, dsn=db_dsn) cursor = connection.cursor() # 创建错误文件 with open(error_file_path, 'w') as error_file: error_count = 0 for stmt in raw_statements: try: # 移除语句末尾的分号(Oracle动态SQL不需要分号) executable_stmt = stmt.rstrip(';') cursor.execute(executable_stmt) print(f"成功执行: {stmt.split()[2]}") # 显示索引名 except cx_Oracle.DatabaseError as e: error_msg = f"错误语句: {stmt}\n错误信息: {e}\n{'=' * 50}\n" print(error_msg) error_file.write(stmt + "\n") error_count += 1 print(f"\n执行完成!错误语句数: {error_count}") print(f"错误语句已保存至: {os.path.abspath(error_file_path)}") except cx_Oracle.DatabaseError as e: print(f"数据库连接失败: {e}") finally: if 'cursor' in locals(): cursor.close() if 'connection' in locals(): connection.close() # 配置参数 config = { "sql_file_path": "C:\Users\Administrator\PycharmProjects\pythonProject\oracle_comments_ghana_cash.sql", # 输入SQL文件 "error_file_path": "failed_indexes.sql", # 错误SQL输出文件 "db_username": "YTF", # 替换为实际用户名 "db_password": "YTF_123456", # 替换为实际密码 "db_dsn": "oracle-1.cfjq6sky0wee.ap-south-1.rds.amazonaws.com:1521:ORCL" # 替换为实际DSN } # 执行函数 execute_index_statements(**config) 报 "sql_file_path": "C:\Users\Administrator\PycharmProjects\pythonProject\oracle_comments_ghana_cash.sql", # 输入SQL文件 ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
最新发布
06-10
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值