主頁 > 軟體工程 > 如何在VGG16中更改批量大小?

如何在VGG16中更改批量大小?

2021-12-05 21:31:27 軟體工程

如何更改 VGG16 中的批量大小?我試圖通過這樣做來解決超出記憶體限制 10% 的問題。

錯誤:

2021-12-03 16:17:07.263665: W tensorflow/core/framework/cpu_allocator_impl.cc:82] Allocation of 4888553472 exceeds 10% of free system memory.

這是我的代碼:

def labelObjectFromImage(image_path, directory_filename):
    img = cv2.imread(image_path directory_filename)
    height = img.shape[0]
    width = img.shape[1]
    channels = img.shape[2]
    img = load_img(image_path directory_filename, target_size=(height, width))
    model = VGG16(weights="imagenet", include_top = False, input_shape = (height, width, channels))
    img = img_to_array(img)
    img = img.reshape((1, img.shape[0], img.shape[1], img.shape[2]))
    img = preprocess_input(img)
    yhat = model.predict(img)
    label = decode_predictions(yhat)
    label = label[0][0]
    print(label)

我嘗試將 model.predict 更改為:

    yhat = model.predict(img, batch_size=1)

但它似乎對嘗試解決問題沒有任何影響

我嘗試使用:

from tensorflow.keras import backend as K

K.clear_session()

但這沒有幫助

我跑了

pip3 uninstall tensorflow-gpu

然后通過安裝正常的tensorflow

pip3 install tensorflow

但這沒有幫助

僅供參考,到目前為止,我在所有這些嘗試中都遇到了相同的錯誤。

正如我所建議的那樣:

    img_resized = tf.image.resize(img, (height, width))

但我現在收到以下錯誤:

Traceback (most recent call last):
  File "organizeSpreadsheet.py", line 105, in <module>
    main()
  File "organizeSpreadsheet.py", line 86, in main
    objects_from_image = labelObjectFromImage(path_to_images, directory_filename)
  File "organizeSpreadsheet.py", line 53, in labelObjectFromImage
    img = img_resized.reshape((1, height, width, channels))
  File "/home/jr/.local/lib/python3.8/site-packages/tensorflow/python/framework/ops.py", line 437, in __getattr__
    raise AttributeError("""
AttributeError: 
        'EagerTensor' object has no attribute 'reshape'.
        If you are looking for numpy-related methods, please run the following:
        from tensorflow.python.ops.numpy_ops import np_config
        np_config.enable_numpy_behavior()

我知道我沒有完全按照指示去做,但它拋出了一個錯誤,所以我遵循了這個建議

我通過進行以下更改更正了錯誤:

def labelObjectFromImage(image_path, directory_filename):
    scale = 60

    img = cv2.imread(image_path directory_filename)
    height = int(img.shape[0] * scale / 100)
    width = int(img.shape[1] * scale / 100)
    channels = img.shape[2]
    #img_resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
    #img_resized = tf.image.resize(img, (height, width))
    tf.image.resize(img, (height, width))
    #img = load_img(image_path directory_filename, target_size=(height, width))
    model = VGG16(weights="imagenet", include_top = False, input_shape = (height, width, channels))
    #img = img_to_array(img)
    #img = img.reshape((1, img.shape[0], img.shape[1], img.shape[2]))
    img = img.reshape((1, height, width, channels))
    img = preprocess_input(img)
    yhat = model.predict(img, batch_size=1)
    label = decode_predictions(yhat)
    label = label[0][0]
    print(label)

但現在我收到錯誤:

ValueError: cannot reshape array of size 63483840 into shape (1,3384,2251,3)

我認為這可以通過嘗試多個尺度來解決,對嗎?

所以我一直在逐一解決這些問題,第一個問題是我沒有安裝cudnn。我按照這些說明來做到這一點。

此外,我按照最新的建議更正了我的代碼。所以現在我的代碼如下所示:

def labelObjectFromImage(image_path, directory_filename):
    scale = 100

    while(1):
        try:
            img = cv2.imread(image_path directory_filename)
            height = int(img.shape[0] * scale / 100)
            width = int(img.shape[1] * scale / 100)
            channels = img.shape[2]
            img = tf.image.resize(img, (height, width))
            model = VGG16(weights="imagenet", include_top = False, input_shape = (height, width, channels))
            img = img.reshape((1, height, width, channels))
            img = preprocess_input(img)
            yhat = model.predict(img, batch_size=1)
            label = decode_predictions(yhat)
            label = label[0][0]
            print(label)
            return label
        except Exception as e:
            print("Error:", e, "scale", scale)
            scale -= 1

對于以后檢查的任何人,請注意此代碼不處理比例低于 0 的情況。這應該在代碼中明確處理。當我正常作業時,我會發布最終結果。

因此,當我按照建議運行代碼時,出現以下錯誤:

Error: 
        'EagerTensor' object has no attribute 'reshape'.
        If you are looking for numpy-related methods, please run the following:
        from tensorflow.python.ops.numpy_ops import np_config
        np_config.enable_numpy_behavior() scale 100

我變了

img = img.reshape((1, height, width, channels))

img = tf.reshape(img, (1, height, width, channels))

并得到以下錯誤:

2021-12-03 18:03:09.909978: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:936] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-12-03 18:03:09.947651: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:936] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-12-03 18:03:09.947958: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:936] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
Num GPUs Available:  1
/usr/local/lib/python3.8/dist-packages/openpyxl/worksheet/_reader.py:312: UserWarning: Unknown extension is not supported and will be removed
  warn(msg)
2021-12-03 18:03:39.195772: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2021-12-03 18:03:39.197491: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:936] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-12-03 18:03:39.197793: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:936] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-12-03 18:03:39.198003: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:936] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-12-03 18:03:39.569744: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:936] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-12-03 18:03:39.569968: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:936] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-12-03 18:03:39.570148: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:936] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2021-12-03 18:03:39.570267: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 4560 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 2060, pci bus id: 0000:01:00.0, compute capability: 7.5
2021-12-03 18:03:50.862568: W tensorflow/core/common_runtime/bfc_allocator.cc:462] Allocator (GPU_0_bfc) ran out of memory trying to allocate 5.04GiB (rounded to 5417287680)requested by op vgg16/block1_conv1/Conv2D
If the cause is memory fragmentation maybe the environment variable 'TF_GPU_ALLOCATOR=cuda_malloc_async' will improve the situation. 
Current allocation summary follows.
Current allocation summary follows.
2021-12-03 18:03:50.862619: I tensorflow/core/common_runtime/bfc_allocator.cc:1010] BFCAllocator dump for GPU_0_bfc
2021-12-03 18:03:50.862648: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (256):  Total Chunks: 23, Chunks in use: 23. 5.8KiB allocated for chunks. 5.8KiB in use in bin. 612B client-requested in use in bin.
2021-12-03 18:03:50.862654: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (512):  Total Chunks: 2, Chunks in use: 2. 1.0KiB allocated for chunks. 1.0KiB in use in bin. 1.0KiB client-requested in use in bin.
2021-12-03 18:03:50.862659: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (1024):     Total Chunks: 5, Chunks in use: 4. 5.2KiB allocated for chunks. 4.2KiB in use in bin. 4.0KiB client-requested in use in bin.
2021-12-03 18:03:50.862666: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (2048):     Total Chunks: 8, Chunks in use: 6. 18.5KiB allocated for chunks. 13.0KiB in use in bin. 12.0KiB client-requested in use in bin.
2021-12-03 18:03:50.862671: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (4096):     Total Chunks: 1, Chunks in use: 1. 6.8KiB allocated for chunks. 6.8KiB in use in bin. 6.8KiB client-requested in use in bin.
2021-12-03 18:03:50.862675: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (8192):     Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2021-12-03 18:03:50.862679: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (16384):    Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2021-12-03 18:03:50.862682: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (32768):    Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2021-12-03 18:03:50.862686: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (65536):    Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2021-12-03 18:03:50.862689: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (131072):   Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2021-12-03 18:03:50.862694: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (262144):   Total Chunks: 2, Chunks in use: 2. 705.0KiB allocated for chunks. 705.0KiB in use in bin. 432.0KiB client-requested in use in bin.
2021-12-03 18:03:50.862715: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (524288):   Total Chunks: 1, Chunks in use: 1. 576.0KiB allocated for chunks. 576.0KiB in use in bin. 576.0KiB client-requested in use in bin.
2021-12-03 18:03:50.862720: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (1048576):  Total Chunks: 1, Chunks in use: 1. 1.97MiB allocated for chunks. 1.97MiB in use in bin. 1.12MiB client-requested in use in bin.
2021-12-03 18:03:50.862746: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (2097152):  Total Chunks: 2, Chunks in use: 2. 4.50MiB allocated for chunks. 4.50MiB in use in bin. 4.50MiB client-requested in use in bin.
2021-12-03 18:03:50.862751: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (4194304):  Total Chunks: 2, Chunks in use: 1. 9.00MiB allocated for chunks. 4.50MiB in use in bin. 4.50MiB client-requested in use in bin.
2021-12-03 18:03:50.862757: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (8388608):  Total Chunks: 6, Chunks in use: 5. 61.79MiB allocated for chunks. 48.29MiB in use in bin. 45.00MiB client-requested in use in bin.
2021-12-03 18:03:50.862761: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (16777216):     Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2021-12-03 18:03:50.862765: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (33554432):     Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2021-12-03 18:03:50.862768: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (67108864):     Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2021-12-03 18:03:50.862786: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (134217728):    Total Chunks: 3, Chunks in use: 2. 726.51MiB allocated for chunks. 484.34MiB in use in bin. 484.34MiB client-requested in use in bin.
2021-12-03 18:03:50.862790: I tensorflow/core/common_runtime/bfc_allocator.cc:1017] Bin (268435456):    Total Chunks: 1, Chunks in use: 0. 3.67GiB allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
2021-12-03 18:03:50.862794: I tensorflow/core/common_runtime/bfc_allocator.cc:1033] Bin for 5.04GiB was 256.00MiB, Chunk State: 
2021-12-03 18:03:50.862814: I tensorflow/core/common_runtime/bfc_allocator.cc:1039]   Size: 3.67GiB | Requested Size: 576.0KiB | in_use: 0 | bin_num: 20, prev:   Size: 242.17MiB | Requested Size: 242.17MiB | in_use: 1 | bin_num: -1
2021-12-03 18:03:50.862817: I tensorflow/core/common_runtime/bfc_allocator.cc:1046] Next region of size 4782227456
2021-12-03 18:03:50.862822: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6000000 of size 256 next 3
2021-12-03 18:03:50.862825: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6000100 of size 256 next 4
2021-12-03 18:03:50.862827: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6000200 of size 256 next 5
2021-12-03 18:03:50.862830: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6000300 of size 256 next 6
2021-12-03 18:03:50.862833: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6000400 of size 256 next 9
2021-12-03 18:03:50.862856: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6000500 of size 256 next 10
2021-12-03 18:03:50.862859: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6000600 of size 256 next 11
2021-12-03 18:03:50.862863: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6000700 of size 256 next 14
2021-12-03 18:03:50.862885: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6000800 of size 256 next 15
2021-12-03 18:03:50.862889: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6000900 of size 512 next 18
2021-12-03 18:03:50.862892: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6000b00 of size 256 next 19
2021-12-03 18:03:50.862895: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6000c00 of size 256 next 20
2021-12-03 18:03:50.862899: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6000d00 of size 256 next 51
2021-12-03 18:03:50.862902: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6000e00 of size 256 next 21
2021-12-03 18:03:50.862933: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6000f00 of size 256 next 24
2021-12-03 18:03:50.862937: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6001000 of size 256 next 25
2021-12-03 18:03:50.862941: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6001100 of size 1024 next 28
2021-12-03 18:03:50.862945: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6001500 of size 256 next 29
2021-12-03 18:03:50.862948: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6001600 of size 256 next 30
2021-12-03 18:03:50.862967: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6001700 of size 1024 next 31
2021-12-03 18:03:50.862971: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] Free  at 7f4da6001b00 of size 1024 next 34
2021-12-03 18:03:50.862974: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6001f00 of size 256 next 36
2021-12-03 18:03:50.862998: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6002000 of size 256 next 37
2021-12-03 18:03:50.863002: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6002100 of size 2048 next 40
2021-12-03 18:03:50.863027: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6002900 of size 256 next 41
2021-12-03 18:03:50.863032: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6002a00 of size 256 next 42
2021-12-03 18:03:50.863036: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] Free  at 7f4da6002b00 of size 3584 next 7
2021-12-03 18:03:50.863055: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6003900 of size 256 next 55
2021-12-03 18:03:50.863059: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6003a00 of size 512 next 16
2021-12-03 18:03:50.863063: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6003c00 of size 1024 next 27
2021-12-03 18:03:50.863094: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6004000 of size 2048 next 33
2021-12-03 18:03:50.863098: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6004800 of size 3072 next 8
2021-12-03 18:03:50.863103: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6005400 of size 2048 next 43
2021-12-03 18:03:50.863107: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6005c00 of size 2048 next 48
2021-12-03 18:03:50.863111: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6006400 of size 2048 next 50
2021-12-03 18:03:50.863115: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] Free  at 7f4da6006c00 of size 2048 next 52
2021-12-03 18:03:50.863119: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6007400 of size 256 next 53
2021-12-03 18:03:50.863124: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6007500 of size 6912 next 54
2021-12-03 18:03:50.863128: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6009000 of size 279552 next 13
2021-12-03 18:03:50.863132: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da604d400 of size 442368 next 17
2021-12-03 18:03:50.863137: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da60b9400 of size 2064384 next 22
2021-12-03 18:03:50.863143: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da62b1400 of size 589824 next 12
2021-12-03 18:03:50.863162: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6341400 of size 11206656 next 35
2021-12-03 18:03:50.863166: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da6df1400 of size 2359296 next 26
2021-12-03 18:03:50.863193: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da7031400 of size 2359296 next 39
2021-12-03 18:03:50.863197: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] Free  at 7f4da7271400 of size 4718592 next 38
2021-12-03 18:03:50.863201: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da76f1400 of size 4718592 next 32
2021-12-03 18:03:50.863226: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] Free  at 7f4da7b71400 of size 14155776 next 45
2021-12-03 18:03:50.863231: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da88f1400 of size 9437184 next 44
2021-12-03 18:03:50.863236: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da91f1400 of size 11115520 next 1
2021-12-03 18:03:50.863240: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da9c8b000 of size 1280 next 2
2021-12-03 18:03:50.863244: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4da9c8b500 of size 9437184 next 47
2021-12-03 18:03:50.863249: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4daa58b500 of size 9437184 next 49
2021-12-03 18:03:50.863253: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] Free  at 7f4daae8b500 of size 253935360 next 56
2021-12-03 18:03:50.863258: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4dba0b7400 of size 253935360 next 46
2021-12-03 18:03:50.863262: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] InUse at 7f4dc92e3300 of size 253935360 next 23
2021-12-03 18:03:50.863267: I tensorflow/core/common_runtime/bfc_allocator.cc:1066] Free  at 7f4dd850f200 of size 3938061824 next 18446744073709551615
2021-12-03 18:03:50.863271: I tensorflow/core/common_runtime/bfc_allocator.cc:1071]      Summary of in-use Chunks by size: 
2021-12-03 18:03:50.863277: I tensorflow/core/common_runtime/bfc_allocator.cc:1074] 23 Chunks of size 256 totalling 5.8KiB
2021-12-03 18:03:50.863282: I tensorflow/core/common_runtime/bfc_allocator.cc:1074] 2 Chunks of size 512 totalling 1.0KiB
2021-12-03 18:03:50.863302: I tensorflow/core/common_runtime/bfc_allocator.cc:1074] 3 Chunks of size 1024 totalling 3.0KiB
2021-12-03 18:03:50.863307: I tensorflow/core/common_runtime/bfc_allocator.cc:1074] 1 Chunks of size 1280 totalling 1.2KiB
2021-12-03 18:03:50.863326: I tensorflow/core/common_runtime/bfc_allocator.cc:1074] 5 Chunks of size 2048 totalling 10.0KiB
2021-12-03 18:03:50.863330: I tensorflow/core/common_runtime/bfc_allocator.cc:1074] 1 Chunks of size 3072 totalling 3.0KiB
2021-12-03 18:03:50.863334: I tensorflow/core/common_runtime/bfc_allocator.cc:1074] 1 Chunks of size 6912 totalling 6.8KiB
2021-12-03 18:03:50.863339: I tensorflow/core/common_runtime/bfc_allocator.cc:1074] 1 Chunks of size 279552 totalling 273.0KiB
2021-12-03 18:03:50.863343: I tensorflow/core/common_runtime/bfc_allocator.cc:1074] 1 Chunks of size 442368 totalling 432.0KiB
2021-12-03 18:03:50.863347: I tensorflow/core/common_runtime/bfc_allocator.cc:1074] 1 Chunks of size 589824 totalling 576.0KiB
2021-12-03 18:03:50.863351: I tensorflow/core/common_runtime/bfc_allocator.cc:1074] 1 Chunks of size 2064384 totalling 1.97MiB
2021-12-03 18:03:50.863355: I tensorflow/core/common_runtime/bfc_allocator.cc:1074] 2 Chunks of size 2359296 totalling 4.50MiB
2021-12-03 18:03:50.863359: I tensorflow/core/common_runtime/bfc_allocator.cc:1074] 1 Chunks of size 4718592 totalling 4.50MiB
2021-12-03 18:03:50.863364: I tensorflow/core/common_runtime/bfc_allocator.cc:1074] 3 Chunks of size 9437184 totalling 27.00MiB
2021-12-03 18:03:50.863368: I tensorflow/core/common_runtime/bfc_allocator.cc:1074] 1 Chunks of size 11115520 totalling 10.60MiB
2021-12-03 18:03:50.863372: I tensorflow/core/common_runtime/bfc_allocator.cc:1074] 1 Chunks of size 11206656 totalling 10.69MiB
2021-12-03 18:03:50.863377: I tensorflow/core/common_runtime/bfc_allocator.cc:1074] 2 Chunks of size 253935360 totalling 484.34MiB
2021-12-03 18:03:50.863381: I tensorflow/core/common_runtime/bfc_allocator.cc:1078] Sum Total of in-use chunks: 544.88MiB
2021-12-03 18:03:50.863385: I tensorflow/core/common_runtime/bfc_allocator.cc:1080] total_region_allocated_bytes_: 4782227456 memory_limit_: 4782227456 available bytes: 0 curr_region_allocation_bytes_: 9564454912
2021-12-03 18:03:50.863391: I tensorflow/core/common_runtime/bfc_allocator.cc:1086] Stats: 
Limit:                      4782227456
InUse:                       571349248
MaxInUse:                    825284608
NumAllocs:                         121
MaxAllocSize:                253935360
Reserved:                            0
PeakReserved:                        0
LargestFreeBlock:                    0

2021-12-03 18:03:50.863400: W tensorflow/core/common_runtime/bfc_allocator.cc:474] **_____***********__________________________________________________________________________________
2021-12-03 18:03:50.863427: W tensorflow/core/framework/op_kernel.cc:1745] OP_REQUIRES failed at conv_ops.cc:684 : RESOURCE_EXHAUSTED: OOM when allocating tensor with shape[1,64,5640,3752] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
Traceback (most recent call last):
  File "organizeSpreadsheet.py", line 107, in <module>
    main()
  File "organizeSpreadsheet.py", line 88, in main
    objects_from_image = labelObjectFromImage(path_to_images, directory_filename)
  File "organizeSpreadsheet.py", line 55, in labelObjectFromImage
    yhat = model.predict(img, batch_size=1)
  File "/home/jr/.local/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/home/jr/.local/lib/python3.8/site-packages/tensorflow/python/eager/execute.py", line 54, in quick_execute
    tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
tensorflow.python.framework.errors_impl.ResourceExhaustedError: Graph execution error:

Detected at node 'vgg16/block1_conv1/Conv2D' defined at (most recent call last):
    File "organizeSpreadsheet.py", line 107, in <module>
      main()
    File "organizeSpreadsheet.py", line 88, in main
      objects_from_image = labelObjectFromImage(path_to_images, directory_filename)
    File "organizeSpreadsheet.py", line 55, in labelObjectFromImage
      yhat = model.predict(img, batch_size=1)
    File "/home/jr/.local/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 64, in error_handler
      return fn(*args, **kwargs)
    File "/home/jr/.local/lib/python3.8/site-packages/keras/engine/training.py", line 1911, in predict
      tmp_batch_outputs = self.predict_function(iterator)
    File "/home/jr/.local/lib/python3.8/site-packages/keras/engine/training.py", line 1730, in predict_function
      return step_function(self, iterator)
    File "/home/jr/.local/lib/python3.8/site-packages/keras/engine/training.py", line 1719, in step_function
      outputs = model.distribute_strategy.run(run_step, args=(data,))
    File "/home/jr/.local/lib/python3.8/site-packages/keras/engine/training.py", line 1712, in run_step
      outputs = model.predict_step(data)
    File "/home/jr/.local/lib/python3.8/site-packages/keras/engine/training.py", line 1680, in predict_step
      return self(x, training=False)
    File "/home/jr/.local/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 64, in error_handler
      return fn(*args, **kwargs)
    File "/home/jr/.local/lib/python3.8/site-packages/keras/engine/base_layer.py", line 1096, in __call__
      outputs = call_fn(inputs, *args, **kwargs)
    File "/home/jr/.local/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 92, in error_handler
      return fn(*args, **kwargs)
    File "/home/jr/.local/lib/python3.8/site-packages/keras/engine/functional.py", line 451, in call
      return self._run_internal_graph(
    File "/home/jr/.local/lib/python3.8/site-packages/keras/engine/functional.py", line 589, in _run_internal_graph
      outputs = node.layer(*args, **kwargs)
    File "/home/jr/.local/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 64, in error_handler
      return fn(*args, **kwargs)
    File "/home/jr/.local/lib/python3.8/site-packages/keras/engine/base_layer.py", line 1096, in __call__
      outputs = call_fn(inputs, *args, **kwargs)
    File "/home/jr/.local/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 92, in error_handler
      return fn(*args, **kwargs)
    File "/home/jr/.local/lib/python3.8/site-packages/keras/layers/convolutional.py", line 248, in call
      outputs = self.convolution_op(inputs, self.kernel)
    File "/home/jr/.local/lib/python3.8/site-packages/keras/layers/convolutional.py", line 233, in convolution_op
      return tf.nn.convolution(
Node: 'vgg16/block1_conv1/Conv2D'
OOM when allocating tensor with shape[1,64,5640,3752] and type float on /job:localhost/replica:0/task:0/device:GPU:0 by allocator GPU_0_bfc
     [[{{node vgg16/block1_conv1/Conv2D}}]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info. This isn't available when running in Eager mode.
 [Op:__inference_predict_function_528]

uj5u.com熱心網友回復:

您已經在使用batch_size = 1。

  1. 通過在匯入 tensorflow 時檢查日志來檢查您是否正在使用 GPU。
  2. 在預測之前嘗試調整影像大小tf.image.resize(image, [small_height,small_width,N_channels])

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/372843.html

標籤:Python 张量流 凯拉斯

上一篇:型別錯誤:由于tensor_scatter_update預期單個張量時的張量串列

下一篇:無法將NumPy陣列轉換為張量(不支持的物件型別numpy.ndarray)錯誤

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • Git本地庫既關聯GitHub又關聯Gitee

    創建代碼倉庫 使用gitee舉例(github和gitee差不多) 1.在gitee右上角點擊+,選擇新建倉庫 ? 2.選擇填寫倉庫資訊,然后進行創建 ? 3.服務端已經準備好了,本地開始作準備 (1)Git 全域設定 git config --global user.name "成鈺" git c ......

    uj5u.com 2020-09-10 05:04:14 more
  • CODING DevOps 代碼質量實戰系列第二課,相約周三

    隨著 ToB(企業服務)的興起和 ToC(消費互聯網)產品進入成熟期,線上故障帶來的損失越來越大,代碼質量越來越重要,而「質量內建」正是 DevOps 核心理念之一。**《DevOps 代碼質量實戰(PHP 版)》**為 CODING DevOps 代碼質量實戰系列的第二課,同時也是本系列的 PHP ......

    uj5u.com 2020-09-10 05:07:43 more
  • 推薦Scrum書籍

    推薦Scrum書籍 直接上干貨,推薦書籍清單如下(推薦有順序的哦) Scrum指南 Scrum精髓 Scrum敏捷軟體開發 Scrum捷徑 硝煙中的Scrum和XP : 我們如何實施Scrum 敏捷軟體開發:Scrum實戰指南 Scrum要素 大規模Scrum:大規模敏捷組織的設計 用戶故事地圖 用 ......

    uj5u.com 2020-09-10 05:07:45 more
  • CODING DevOps 代碼質量實戰系列最后一課,周四發車

    隨著 ToB(企業服務)的興起和 ToC(消費互聯網)產品進入成熟期,線上故障帶來的損失越來越大,代碼質量越來越重要,而「質量內建」正是 DevOps 核心理念之一。 **《DevOps 代碼質量實戰(Java 版)》**為 CODING DevOps 代碼質量實戰系列的最后一課,同時也是本系列的 ......

    uj5u.com 2020-09-10 05:07:52 more
  • 敏捷軟體工程實踐書籍

    Scrum轉型想要做好,第一步先了解并真正落實Scrum,那么我推薦的Scrum書籍是要看懂并實踐的。第二步是團隊的工程實踐要做扎實。 下面推薦工程實踐書單: 重構:改善既有代碼的設計 決議極限編程 : 擁抱變化 代碼整潔代碼 程式員的職業素養 修改代碼的藝術 撰寫可讀代碼的藝術 測驗驅動開發 : ......

    uj5u.com 2020-09-10 05:07:55 more
  • Jenkins+svn+nginx實作windows環境自動部署vue前端專案

    前面文章介紹了Jenkins+svn+tomcat實作自動化部署,現在終于有空抽時間出來寫下Jenkins+svn+nginx實作自動部署vue前端專案。 jenkins的安裝和配置已經在前面文章進行介紹,下面介紹實作vue前端專案需要進行的哪些額外的步驟。 注意:在安裝jenkins和nginx的 ......

    uj5u.com 2020-09-10 05:08:49 more
  • CODING DevOps 微服務專案實戰系列第一課,明天等你

    CODING DevOps 微服務專案實戰系列第一課**《DevOps 微服務專案實戰:DevOps 初體驗》**將由 CODING DevOps 開發工程師 王寬老師 向大家介紹 DevOps 的基本理念,并探討為什么現代開發活動需要 DevOps,同時將以 eShopOnContainers 項 ......

    uj5u.com 2020-09-10 05:09:14 more
  • CODING DevOps 微服務專案實戰系列第二課來啦!

    近年來,工程專案的結構越來越復雜,需要接入合適的持續集成流水線形式,才能滿足更多變的需求,那么如何優雅地使用 CI 能力提升生產效率呢?CODING DevOps 微服務專案實戰系列第二課 《DevOps 微服務專案實戰:CI 進階用法》 將由 CODING DevOps 全堆疊工程師 何晨哲老師 向 ......

    uj5u.com 2020-09-10 05:09:33 more
  • CODING DevOps 微服務專案實戰系列最后一課,周四開講!

    隨著軟體工程越來越復雜化,如何在 Kubernetes 集群進行灰度發布成為了生產部署的”必修課“,而如何實作安全可控、自動化的灰度發布也成為了持續部署重點關注的問題。CODING DevOps 微服務專案實戰系列最后一課:**《DevOps 微服務專案實戰:基于 Nginx-ingress 的自動 ......

    uj5u.com 2020-09-10 05:10:00 more
  • CODING 儀表盤功能正式推出,實作作業資料可視化!

    CODING 儀表盤功能現已正式推出!該功能旨在用一張張統計卡片的形式,統計并展示使用 CODING 中所產生的資料。這意味著無需額外的設定,就可以收集歸納寶貴的作業資料并予之量化分析。這些海量的資料皆會以圖表或串列的方式躍然紙上,方便團隊成員隨時查看各專案的進度、狀態和指標,云端協作迎來真正意義上 ......

    uj5u.com 2020-09-10 05:11:01 more
最新发布
  • windows系統git使用ssh方式和gitee/github進行同步

    使用git來clone專案有兩種方式:HTTPS和SSH:
    HTTPS:不管是誰,拿到url隨便clone,但是在push的時候需要驗證用戶名和密碼;
    SSH:clone的專案你必須是擁有者或者管理員,而且需要在clone前添加SSH Key。SSH 在push的時候,是不需要輸入用戶名的,如果配置... ......

    uj5u.com 2023-04-19 08:41:12 more
  • windows系統git使用ssh方式和gitee/github進行同步

    使用git來clone專案有兩種方式:HTTPS和SSH:
    HTTPS:不管是誰,拿到url隨便clone,但是在push的時候需要驗證用戶名和密碼;
    SSH:clone的專案你必須是擁有者或者管理員,而且需要在clone前添加SSH Key。SSH 在push的時候,是不需要輸入用戶名的,如果配置... ......

    uj5u.com 2023-04-19 08:35:34 more
  • 2023年農牧行業6大CRM系統、5大場景盤點

    在物聯網、大資料、云計算、人工智能、自動化技術等現代資訊技術蓬勃發展與逐步成熟的背景下,數字化正成為農牧行業供給側結構性變革與高質量發展的核心驅動因素。因此,改造和提升傳統農牧業、開拓創新現代智慧農牧業,加快推進農牧業的現代化、資訊化、數字化建設已成為農牧業發展的重要方向。 當下,企業數字化轉型已經 ......

    uj5u.com 2023-04-18 08:05:44 more
  • 2023年農牧行業6大CRM系統、5大場景盤點

    在物聯網、大資料、云計算、人工智能、自動化技術等現代資訊技術蓬勃發展與逐步成熟的背景下,數字化正成為農牧行業供給側結構性變革與高質量發展的核心驅動因素。因此,改造和提升傳統農牧業、開拓創新現代智慧農牧業,加快推進農牧業的現代化、資訊化、數字化建設已成為農牧業發展的重要方向。 當下,企業數字化轉型已經 ......

    uj5u.com 2023-04-18 08:00:18 more
  • 計算機組成原理—存盤器

    計算機組成原理—硬體結構 二、存盤器 1.概述 存盤器是計算機系統中的記憶設備,用來存放程式和資料 1.1存盤器的層次結構 快取-主存層次主要解決CPU和主存速度不匹配的問題,速度接近快取 主存-輔存層次主要解決存盤系統的容量問題,容量接近與價位接近于主存 2.主存盤器 2.1概述 主存與CPU的聯 ......

    uj5u.com 2023-04-17 08:20:31 more
  • 談一談我對協同開發的一些認識

    如今各互聯網公司普通都使用敏捷開發,采用小步快跑的形式來進行專案開發。如果是小專案或者小需求,那一個開發可能就搞定了。但對于電商等復雜的系統,其功能多,結構復雜,一個人肯定是搞不定的,所以都是很多人來共同開發維護。以我曾經待過的商城團隊為例,光是后端開發就有七十多人。 為了更好地開發這類大型系統,往 ......

    uj5u.com 2023-04-17 08:18:55 more
  • 專案管理PRINCE2核心知識點整理

    PRINCE2,即 PRoject IN Controlled Environment(受控環境中的專案)是一種結構化的專案管理方法論,由英國政府內閣商務部(OGC)推出,是英國專案管理標準。
    PRINCE2 作為一種開放的方法論,是一套結構化的專案管理流程,描述了如何以一種邏輯性的、有組織的方法,... ......

    uj5u.com 2023-04-17 08:18:51 more
  • 談一談我對協同開發的一些認識

    如今各互聯網公司普通都使用敏捷開發,采用小步快跑的形式來進行專案開發。如果是小專案或者小需求,那一個開發可能就搞定了。但對于電商等復雜的系統,其功能多,結構復雜,一個人肯定是搞不定的,所以都是很多人來共同開發維護。以我曾經待過的商城團隊為例,光是后端開發就有七十多人。 為了更好地開發這類大型系統,往 ......

    uj5u.com 2023-04-17 08:18:00 more
  • 專案管理PRINCE2核心知識點整理

    PRINCE2,即 PRoject IN Controlled Environment(受控環境中的專案)是一種結構化的專案管理方法論,由英國政府內閣商務部(OGC)推出,是英國專案管理標準。
    PRINCE2 作為一種開放的方法論,是一套結構化的專案管理流程,描述了如何以一種邏輯性的、有組織的方法,... ......

    uj5u.com 2023-04-17 08:17:55 more
  • 計算機組成原理—存盤器

    計算機組成原理—硬體結構 二、存盤器 1.概述 存盤器是計算機系統中的記憶設備,用來存放程式和資料 1.1存盤器的層次結構 快取-主存層次主要解決CPU和主存速度不匹配的問題,速度接近快取 主存-輔存層次主要解決存盤系統的容量問題,容量接近與價位接近于主存 2.主存盤器 2.1概述 主存與CPU的聯 ......

    uj5u.com 2023-04-17 08:12:06 more