我用的版本情况:

tensorflow                   2.9.1
tensorflow-estimator         2.9.0rc0
tensorflow-io-gcs-filesystem 0.26.0
tensorflow-probability       0.14.0

d2l                          0.17.5

numpy                        1.21.5

先看代码:

import numpy as np
import tensorflow as tf
import tensorflow_probability as tfp
from d2l import tensorflow as d2l
fair_probs = tf.ones(6) / 6
print(tfp.distributions.Multinomial(1, fair_probs).sample())

出现的问题:

2022-10-10 16:43:34.068891: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX AVX2
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-10-10 16:43:34.581276: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1532] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 9622 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 3060, pci bus id: 0000:01:00.0, compute capability: 8.6
2022-10-10 16:43:35.048171: I tensorflow/stream_executor/cuda/cuda_driver.cc:739] failed to allocate 9.40G (10090381312 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
2022-10-10 16:43:35.104772: I tensorflow/stream_executor/cuda/cuda_driver.cc:739] failed to allocate 8.46G (9081342976 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
2022-10-10 16:43:35.160408: I tensorflow/stream_executor/cuda/cuda_driver.cc:739] failed to allocate 7.61G (8173208576 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
2022-10-10 16:43:35.214926: I tensorflow/stream_executor/cuda/cuda_driver.cc:739] failed to allocate 6.85G (7355887616 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
2022-10-10 16:43:35.269709: I tensorflow/stream_executor/cuda/cuda_driver.cc:739] failed to allocate 6.17G (6620298752 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
2022-10-10 16:43:35.323338: I tensorflow/stream_executor/cuda/cuda_driver.cc:739] failed to allocate 5.55G (5958268928 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
2022-10-10 16:43:35.376212: I tensorflow/stream_executor/cuda/cuda_driver.cc:739] failed to allocate 4.99G (5362441728 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
2022-10-10 16:43:35.431199: I tensorflow/stream_executor/cuda/cuda_driver.cc:739] failed to allocate 4.49G (4826197504 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
2022-10-10 16:43:35.487270: I tensorflow/stream_executor/cuda/cuda_driver.cc:739] failed to allocate 4.04G (4343577600 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory
2022-10-10 16:43:35.541850: I tensorflow/stream_executor/cuda/cuda_driver.cc:739] failed to allocate 3.64G (3909219840 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY: out of memory

Process finished with exit code -1073740791 (0xC0000409)

红色字体总结:爆GPU了,用的是3060,12g。

解决方案:

import numpy as np
import tensorflow as tf
import tensorflow_probability as tfp
from d2l import tensorflow as d2lconfig = tf.compat.v1.ConfigProto(allow_soft_placement=False, log_device_placement=False)
config.gpu_options.allow_growth = True
session = tf.compat.v1.Session(config=config)fair_probs = tf.ones(6) / 6
print(tfp.distributions.Multinomial(1, fair_probs).sample())

把上面中间这段的代码加上去就ok。

再跑一下,出结果了

李沐动手学深度学习概率部分报错相关推荐

  1. 李沐动手学深度学习V2-全卷积网络FCN和代码实现

    一.全卷积网络FCN 1. 介绍 语义分割是对图像中的每个像素分类,全卷积网络(fully convolutional network,FCN)采用卷积神经网络实现了从图像像素到像素类别的变换 ,与前 ...

  2. 李沐动手学深度学习v2/总结1

    总结 编码过程 数据 数据预处理 模型 参数,初始化参数 超参数 损失函数,先计算损失,清空梯度(防止有累积的梯度),再对损失后向传播计算损失关于参数的梯度 优化算法,使用优化算法更新参数 训练求参数 ...

  3. 李沐动手学深度学习(pytorch版本)d2lzh_pytorch包的缺少安装问题

    学习深度学习时候,很多人参考的是李沐的动手学深度学习Pytorch版本(附上官方地址:https://tangshusen.me/Dive-into-DL-PyTorch/#/). 在学习3.5.1节 ...

  4. 【李沐动手学深度学习】读书笔记 01前言

    虽然之前已经学过这部分内容和深度学习中的基础知识,但总觉得学的不够系统扎实,所以希望再通过沐神的课程以及书籍,系统条理的学习一遍.在读书过程中,利用导图做了一下梳理,形成了这个读书笔记.如有侵权,请联 ...

  5. 关于李沐动手学深度学习(d2l)pytorch环境本地配置

    本地安装d2l 由于之前试了很多次d2l课本的安装方法失败了,这里提供一种我可以成功安装d2l包的方法. pytorch安装 首先安装cuda.cudnn.pytroch(gpu版本).可以参考这篇文 ...

  6. 李沐动手学深度学习:08 线性回归(代码逐行理解)

    目录 一.相关资料连接 1.1 李沐视频 1.2 代码.PPT 二.代码及笔记(使用Jupyter Notebook) 2.1 线性回归从零开始实现 2.1.1 基本概念 2.1.2 基础优化算法 2 ...

  7. windows上配置深度学习(李沐-动手学深度学习)

    1.安装miniconda windows下安装,去清华大学开源镜像下载,速度比较快. 选中Miniconda3-latest-Windos-x86_64.exe下载安装包(目前最新的是py3.9) ...

  8. 李沐动手学深度学习第四章-4.9.环境和分布偏移

    我们从来没有想过数据最初从哪里来?以及我们计划最终如何处理模型的输出? 根据测试集的精度衡量,模型表现得非常出色. 但是当数据分布突然改变时,模型在部署中会出现灾难性的失败. 解决方案很简单(要求&q ...

  9. 3.4 Softmax回归【李沐动手学深度学习】

    目录 1. 从回归到多分类--均方损失 Softmax回归 2. Softmax和交叉熵损失 损失 梯度 3. 损失函数 3.1 均方损失(L2 Loss) 3.2 绝对值损失函数(L1 Loss) ...

最新文章

  1. 如何避免Java中的回调“地狱”
  2. PHP开发调试环境配置(基于wampserver+Eclipse for PHP Developers )
  3. 等了这么久,就给我看这个?
  4. 文献记录(part90)--A novel density-based clustering algorithm using nearest neighbor graph
  5. LeetCode 1104. 二叉树寻路(数学位运算)
  6. 统计一个长度为2的子字符串在另一个字符串中出现的次数.例如:假定输入的字符串为“asd asasdfg asd as zx67 asd mklo”,子字符串为“as”,函数返回值为6。
  7. SSH2整合需要jar包解释
  8. PSP金手指CMF_r21d修改版安装方法
  9. 最短路经典 昂贵的聘礼(1062)
  10. java即时聊天系统_基于Java技术的即时聊天系统实现(含源文件).doc
  11. sonar报java.io.StreamCorruptedException: invalid internal transport message format, got (48,54,54,50)
  12. 【转】卡巴斯基2011导入key专用工具+卡巴斯基提取key工具(激活码转换key)
  13. 网页鼠标指针样式(cursor属性)
  14. 复选框样式圆圈html,css怎么美化复选框样式
  15. Qt编写安防视频监控系统23-图片地图
  16. 如何把团队带成一盘散沙?
  17. 阿里万亿交易量级下的秒级监控
  18. 知识图谱是什么,知识图谱有什么特点?
  19. C4D——建宜家小闹钟
  20. 让自己不烦心的心理暗示

热门文章

  1. Dynaform 6.0安装说明教程
  2. 消费新品周报 | 李宁推出超轻16代跑鞋;天梭表发布11款全新腕间时计作品
  3. MySQL建设用地信息系统_关于 “一站式规划管理服务平台” 工改系统数据互联互通公开询价函...
  4. winxp怎么登陆云服务器_阿里云ECS云服务器能否导入使用自己本地windows7或winxp操作系统镜像?...
  5. docker介绍+下载+基础操作---ubuntu/centos
  6. Java SE 基础知识体系梳理
  7. 【SpringBoot-3】切面AOP实现权限校验:实例演示与注解全解
  8. XXL-JOB入门教学
  9. 访问控制列表--基于时间的ACL、动态ACL
  10. 如何查看win10是否永久激活