报错解决:InvalidArgumentError: Can not squeeze dim[1], expected a dimension of 1, got
报错解决:InvalidArgumentError: Can not squeeze dim[1], expected a dimension of 1, got 101
晚上在使用tensorflow时报错如下:
Traceback (most recent call last):File "C:\Users\peter\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 786, in runfileexecfile(filename, namespace)File "C:\Users\peter\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfileexec(compile(f.read(), filename, 'exec'), namespace)callbacks = [cp_callback]) # pass callback to trainingFile "C:\Users\peter\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py", line 880, in fitvalidation_steps=validation_steps)File "C:\Users\peter\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\training_arrays.py", line 329, in model_iterationbatch_outs = f(ins_batch)File "C:\Users\peter\Anaconda3\lib\site-packages\tensorflow\python\keras\backend.py", line 3076, in __call__run_metadata=self.run_metadata)File "C:\Users\peter\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1439, in __call__run_metadata_ptr)File "C:\Users\peter\Anaconda3\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 528, in __exit__c_api.TF_GetCode(self.status.status))InvalidArgumentError: Can not squeeze dim[1], expected a dimension of 1, got 101[[{{node metrics/acc/Squeeze}}]][[{{node loss/dense_loss/broadcast_weights/assert_broadcastable/is_valid_shape/has_valid_nonscalar_shape/has_invalid_dims/concat}}]]
这个错误是因为TensorFlow的Y的标签必须只包括0,1,2等类索引,而不是像[1,0,0],[0,1,0],[0,0,1]这样的单一热编码。
转换代码如下:
import numpy as np
import tensorflow as tfdef change_to_right(wrong_labels):right_labels=[]for x in wrong_labels:for i in range(0,len(wrong_labels[0])):if x[i]==1:right_labels.append(i+1)return right_labelswrong_labels =np.array([[0,0,1,0], [0,0,1,0], [1,0,0,0],[0,1,0,0]])
right_labels =tf.convert_to_tensor(np.array(change_to_right(wrong_labels)))
报错解决:InvalidArgumentError: Can not squeeze dim[1], expected a dimension of 1, got相关推荐
- InvalidArgumentError: Can not squeeze dim[1], expected a dimension of 1, got 10 for metrics/acc/
报错代码显示: InvalidArgumentError: Can not squeeze dim[1], expected a dimension of 1, got 10 for 'metrics ...
- Can not squeeze dim[1], expected a dimension of 1
遇上如题所示问题,多半是因为使用了sparse_categorical_crossentropy作为损失函数 这会出现在分类问题中,这个激活函数要求如下: labels vector must pro ...
- tensorflow报错Can not squeeze dim[1], expected a dimension of 1, got n for解决办法
这是因为tf的文档要求label必须是一个单独的值,而不是一个one-hot编码后像[1,0,0], [0,1,0], [0,0,1].的值.
- 报错解决:InvalidArgumentError: Received a label value of 101 which is outside the valid range of [0, 101
报错解决:InvalidArgumentError: Received a label value of 101 which is outside the valid range of [0, 101 ...
- 连接远程服务器CredSSP加密Oracle修正报错解决办法
连接远程服务器CredSSP加密Oracle修正报错解决办法: 打开注册表,快捷输入 "regedit"(类似找命令提示符 输入 cmd 一样)找文件夹 路径:HKLM(缩写)\S ...
- 从零开始在ubuntu上安装和使用k8s集群及报错解决
文章目录 安装docker 安装kubernetes 配置k8s集群 配置虚拟机网络 配置Master节点的k8s网络 拉取k8s需要的镜像 启动 kubeadm 和 kubelet 配置 node节 ...
- Linux/ubuntu 安装 redis 4.0报错解决:redis-server.service: Can't open PID file /var/run/redis/redis-server.
此文首发于我的个人博客:Linux/ubuntu 安装 redis 4.0报错解决:redis-server.service: Can't open PID file /var/run/redis/r ...
- Python-PyCharm 报错解决:ImportError: cannot import name 'InteractiveConsole' from 'code'
此文首发于我的个人博客:Python-PyCharm 报错解决:ImportError: cannot import name 'InteractiveConsole' from 'code' - z ...
- 报错解决:RequestsDependencyWarning: urllib3 (1.24.3) or chardet (3.0.4) doesn't match a supported versio
此文首发于我的个人博客:报错解决 RequestsDependencyWarning urllib3 (1.24.3) or chardet (3.0.4) doesn't match a suppo ...
最新文章
- 常见Java集合的实现细节
- python爬虫常见报错_Python爬虫常见HTTP响应状态码详解
- 深度学习(11)TensorFlow基础操作七: 向前传播(张量)实战
- 快放弃你的管家软件吧! Part 2 强制删除
- 悉数11种主流NoSQL文档型数据库
- HDOJ 1021-1025
- docker安装(一)
- iif能用到mysql中吗_数据库 iif
- 机器人收集 + Keypose 算法:准确估计透明物体的 3D 姿态
- 【经验总结】js关闭当前页面/关闭当前窗口(兼容所有浏览器)
- hbase 使用lzo_【hbase】Hbase最佳实践
- java高并发之线程池
- arcview、arcinfo、arceditor的区别
- CSDN首页 云计算 孙玄:解析58同城典型技术架构及演变
- 迁移学习 Transfer Learning(可能是目前最全的迁移学习资料库?)
- FPGA学习任意波函数信号发生器的设计(基于quartus II13.0)
- 2021年6月上市公司新闻舆论事件分析报告合集
- Linux资源控制-使用cgroup控制CPU和内存
- excel通过合并单元格“增加行高”(大于最大行高409)
- 使用二进制包在生产环境部署 Kubernetes v1.13.2 集群
热门文章
- 第三十课.向量胶囊与动态路由
- intel 82579v驱动下载_最新INTEL和AMD平台轻松安装WIN7,集成M.2和USB3.0驱动
- iMeta期刊投审稿系统ScholarOne正式上线
- 一文掌握Conda软件安装:虚拟环境、软件通道、加速solving、跨服务器迁移
- QIIME 2用户文档. 12数据筛选Filtering data(2019.7)
- 3分和30分文章差距在哪里?
- Nature :全球表层土壤中微生物组的结构和功能
- Google Chrome插件导出与安装
- R语言ggplot2可视化分面图(faceting)、可视化分面条形图(facet_wrap bar plot)、使用strip.text函数自定义分面图每个分面标题条带strip的大小(cutomi
- R语言使用Rtsne包进行TSNE分析:通过数据类型筛选数值数据、scale函数进行数据标准化缩放、提取TSNE分析结果合并到原dataframe中(tSNE with Rtsne package)