在Mac上将文件复制到RAM(Python)

时间:2015-05-27 05:41:32

标签: python linux macos unix conv-neural-network

我正在运行一些构建一个convnet的用户的代码。早期功能尝试通过运行:

将火车和测试图像复制到/dev/shm
import os
import time

paths = ["data/raw/images_train_rev1", "data/raw/images_test_rev1"]

for path in paths:
    if os.path.exists(os.path.join("/dev/shm",os.path.basename(path))):
        print "%s exists in /dev/shm, skipping." % path
        continue

    print "Copying %s to /dev/shm..." % path
    start_time = time.time()
    os.system("cp -R %s /dev/shm/" % path)
    print "  took %.2f seconds." % (time.time() - start_time)

我收到了错误:

cp: /dev/shm: Permission denied
cp: data/raw/images_test_rev1: unable to copy extended attributes to 
/dev/shm: No such file or directory

我可以在Mac上使用/dev/shm的替代品吗?

我使用以下信息在OSX中创建了一个ramdisk:

http://osxdaily.com/2007/03/23/create-a-ram-disk-in-mac-os-x/

然后:     ls -lah / dev / rdisk1     crw ------- 1 xxxx staff 1,4 4月25日16:26 / dev / rdisk1

但是,当我尝试写入时,我收到错误:

/rdisk1 is not a directory
took 0.78 seconds.
Copying data/raw/images_test_rev1 to /dev/rdisk1...
cp: /dev/rdisk1 is not a directory
took 0.02 seconds.

希望你能提供帮助。谢谢。

1 个答案:

答案 0 :(得分:2)

您可以使用此实用程序https://gist.github.com/koshigoe/822455

cd /tmp
git clone https://gist.github.com/822455.git
cd 822455
chmod +x *
sudo ./mount-ram.sh /dev/shm 1024 
sudo chmod 777 /dev/shm

它将在RAM中创建1G的可写/dev/shm文件夹