如何在 Tensorflow 中设置 batch_size 属性

Posted

技术标签:

【中文标题】如何在 Tensorflow 中设置 batch_size 属性【英文标题】:How to set batch_size attribute in Tensorflow 【发布时间】:2020-04-14 16:23:14 【问题描述】:

我正在使用 C# 和 ML.NET 来创建图像分类。它工作正常,但是当我在 Linux VM(只有 0.6GB 内存)上运行代码时,有时在使用模型预测图像时会出现此错误。

2019-12-23 10:58:01.912720: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-12-23 10:58:02.511549: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2300000000 Hz
2019-12-23 10:58:02.513308: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x7f096cb2ff80 executing computations on platform Host. Devices:
2019-12-23 10:58:02.513353: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
2019-12-23 10:58:04.094413: W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1412] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA_FLAGS=--tf_xla_cpu_global_jit was not set.  If you want XLA:CPU, either set that envvar, or use experimental_jit_scope to enable XLA:CPU.  To confirm that XLA is active, pass --vmodule=xla_compilation_cache=1 (as a proper command-line flag, not via TF_XLA_FLAGS) or set the envvar XLA_FLAGS=--xla_hlo_profile.
2019-12-23 10:58:04.212846: W tensorflow/core/framework/allocator.cc:107] Allocation of 8576064 exceeds 10% of system memory.
2019-12-23 10:58:04.295982: W tensorflow/core/framework/allocator.cc:107] Allocation of 8388608 exceeds 10% of system memory.
2019-12-23 10:58:04.301122: W tensorflow/core/framework/allocator.cc:107] Allocation of 9437184 exceeds 10% of system memory.
2019-12-23 10:58:04.305958: W tensorflow/core/framework/allocator.cc:107] Allocation of 9437184 exceeds 10% of system memory.
2019-12-23 10:58:04.310375: W tensorflow/core/framework/allocator.cc:107] Allocation of 9437184 exceeds 10% of system memory.

其他时候屏幕只是简单地终止,没有错误消息。

我查看了有关此的其他问题,发现建议将batch_size降低到一个较小的数字,但我找不到这个设置的位置。

我在哪里可以编辑这个值?

【问题讨论】:

我不是专家。但是只有 0.6GB 内存的图像分类听起来真的很低:D 我在docs.microsoft.com/en-us/dotnet/machine-learning 上找不到任何东西,所以我猜你必须给它足够的内存才能完成这项工作。您可能可以使它与磁盘交换内存。但这会让一切变得非常缓慢。 尝试减小批量大小。当前值是多少? @Parth Bhuva 我非常感谢您的意见,虽然我很想减少批量大小,但我不知道如何,这正是这个问题的意义所在。 @Kiksen 是的,我同意,但我认为它正在终止,因为它决定 10% 的使用量太大或其他什么,不幸的是,我无法在 VM 上获得更多内存。跨度> 【参考方案1】:

点击here ,这解释了如何使用自定义批量大小为张量流模型创建自己的输入批量

【讨论】:

以上是关于如何在 Tensorflow 中设置 batch_size 属性的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Fashion_mnist (Tensorflow) 中设置具有特定类别的子集

如何在 Tensorflow 中设置分层学习率?

如何在 Tensorflow 中设置分层学习率?

Tensorflow 在 jupyter 中设置 CUDA_VISIBLE_DEVICES

如何在 Tensorflow C++ 中设置 inter_op_parallelism_threads 和 intra_op_parallelism_threads 以进行 Seesion 配置

我是不是需要在导入 numpy 或 tensorflow 的所有模块中设置种子?