I write some code
batch = np.ones([4, 3, 224, 224], dtype="float32")
import time
s = time.time()
batch_bytes = batch.tobytes()
e = time.time()
print(f"{(e-s)*1e3} ms")
this gives output of 2.2954940795898438 ms
Seems a not small cost, I guess this method makes a copy of data bytes?
I used to think that the data are stored in bytes in memory so that there is a method to directly get it?
So is it possible to get the bytes more efficiently?