在Google Colab中拆分文件以进行训练和测试

时间:2019-02-28 12:30:29

标签: deep-learning conv-neural-network google-colaboratory

我已经在本地jupyter笔记本上成功地训练和测试了我的模型,但是我想在Google Colab中尝试与尝试其他昂贵的CNN模型相同的代码。 有人可以帮我这里有什么问题吗?我已经从Google云端硬盘在Google Colab环境中上传了文件。在这里,我想从100个文件夹中分割文件以进行训练和测试,但是每次出现“没有这样的文件或目录”的错误。

folder = 'sample_data/firmasSINTESISmanuscritas'
number_of_users = 100
count_of_users = 0
for dir in os.listdir(folder):
print(dir)
filenames = [
    #os.path.join(os.path.dirname(os.path.abspath(__file__)), folder+'\\'+dir, i) for i in os.listdir(folder+'\\'+dir)
    os.path.join(folder+'\\'+dir, i) for i in os.listdir(folder+'\\'+dir)
]
filenames = filenames[:-1]

labels = [filename.__contains__('c-') for filename in filenames]
labels = np.array(labels, dtype=bool).astype(int).tolist()

x_train, x_test, y_train, y_test = train_test_split(filenames, labels, test_size=0.3, random_state=42)

filenames_train = filenames_train + x_train
filenames_test = filenames_test + x_test
Y_train = Y_train + y_train
Y_test = Y_test + y_test

count_of_users += 1
if number_of_users <= count_of_users:
    break
print('end')

[Error][1]

1 个答案:

答案 0 :(得分:0)

您是否已经将Google驱动器安装到colab来访问这些文件?否则,请按照 this blog post中提到的命令进行操作。