Skip to content

Instantly share code, notes, and snippets.

@Dobiasd

Dobiasd/asd.md Secret

Created April 12, 2024 11:52
Show Gist options
  • Save Dobiasd/dd6956cc98ee3f4f4643eae0ccd8a7eb to your computer and use it in GitHub Desktop.
Save Dobiasd/dd6956cc98ee3f4f4643eae0ccd8a7eb to your computer and use it in GitHub Desktop.
import numpy as np
import psutil
import tensorflow as tf

model = tf.keras.applications.ResNet152V2()
for run in range(10000):
    images = np.zeros([run % 100 + 1, 224, 224, 3], dtype=np.uint8)
    memory_usage_in_MiB = psutil.Process().memory_info().rss / (1024 * 1024)
    print(f"Memory usage after {run} run(s) (in MiB): {memory_usage_in_MiB:.3f}", flush=True)
    model.predict(images, verbose=0)
Memory usage after 0 run(s) (in MiB): 783.898
Memory usage after 1 run(s) (in MiB): 843.965
Memory usage after 2 run(s) (in MiB): 905.809
Memory usage after 3 run(s) (in MiB): 926.613
Memory usage after 4 run(s) (in MiB): 929.820
Memory usage after 5 run(s) (in MiB): 988.938
Memory usage after 6 run(s) (in MiB): 1022.199
Memory usage after 7 run(s) (in MiB): 1030.844
Memory usage after 8 run(s) (in MiB): 1035.547
Memory usage after 9 run(s) (in MiB): 1075.227
Memory usage after 10 run(s) (in MiB): 1080.125
Memory usage after 11 run(s) (in MiB): 1085.094
Memory usage after 12 run(s) (in MiB): 1064.848
Memory usage after 13 run(s) (in MiB): 1082.512
Memory usage after 14 run(s) (in MiB): 1094.887
Memory usage after 15 run(s) (in MiB): 1102.629
Memory usage after 16 run(s) (in MiB): 1122.195
Memory usage after 17 run(s) (in MiB): 1101.715
Memory usage after 18 run(s) (in MiB): 1118.234
Memory usage after 19 run(s) (in MiB): 1120.234
Memory usage after 20 run(s) (in MiB): 1136.480
...
Memory usage after 409 run(s) (in MiB): 1254.375
Memory usage after 410 run(s) (in MiB): 1260.383
Memory usage after 713 run(s) (in MiB): 1297.750
Memory usage after 714 run(s) (in MiB): 1300.977
Memory usage after 715 run(s) (in MiB): 1303.609
...
Memory usage after 3117 run(s) (in MiB): 1329.902
Memory usage after 3118 run(s) (in MiB): 1357.523
...

Dockerfile to reproduce:

FROM python:3.11.8

RUN pip3 install tensorflow==2.16.1 psutil==5.9.8

RUN echo 'import numpy as np\n\
import psutil\n\
import tensorflow as tf\n\
model = tf.keras.applications.ResNet152V2()\n\
for run in range(10000):\n\
    images = np.zeros([run % 100 + 1, 224, 224, 3], dtype=np.uint8)\n\
    memory_usage_in_MiB = psutil.Process().memory_info().rss / (1024 * 1024)\n\
    print(f"Memory usage after {run} run(s) (in MiB): {memory_usage_in_MiB:.3f}", flush=True)\n\
    model.predict(images, verbose=0)' > main.py

ADD "https://www.random.org/cgi-bin/randbyte?nbytes=10&format=h" skipcache
RUN python3 main.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment