gpt4 book ai didi

python - FileNotFoundError : No such file: -> Error occuring due to TimeOut of Google Drive?

转载 作者:行者123 更新时间:2023-12-03 07:52:13 28 4
gpt4 key购买 nike

我用Sequence类创建了一个DataGenerator

import tensorflow.keras as keras
from skimage.io import imread
from skimage.transform import resize
import numpy as np
import math
from tensorflow.keras.utils import Sequence

Here, `x_set` is list of path to the images and `y_set` are the associated classes.

class DataGenerator(Sequence):
def __init__(self, x_set, y_set, batch_size):
self.x, self.y = x_set, y_set
self.batch_size = batch_size

def __len__(self):
return math.ceil(len(self.x) / self.batch_size)

def __getitem__(self, idx):
batch_x = self.x[idx * self.batch_size:(idx + 1) *
self.batch_size]
batch_y = self.y[idx * self.batch_size:(idx + 1) *
self.batch_size]

return np.array([
resize(imread(file_name), (224, 224))
for file_name in batch_x]), np.array(batch_y)
然后,将其应用于训练和验证数据。 X_train是一个字符串列表,其中包含训练数据的图像路径。 y_train是训练数据的单编码标签。验证数据也是如此。
我使用以下代码创建了图像路径:
X_train = []
for name in train_FileName:
file_path = r"/content/gdrive/My Drive/data/2017-IWT4S-CarsReId_LP-dataset/" + name
X_train.append(file_path)
之后,我将 DataGenerator应用于训练和验证数据:
training_generator = DataGenerator(X_train, y_train, batch_size=32)
validation_generator = DataGenerator(X_val, y_val, batch_size=32)
之后,我使用 fit_generator方法运行模型:
model.fit_generator(generator=training_generator,
validation_data=validation_generator,
steps_per_epoch = num_train_samples // 32,
validation_steps = num_val_samples // 32,
epochs = 10,
use_multiprocessing=True,
workers=2)
在CPU上第一次运行良好,初始化了我的模型并开始了第一个纪元。然后,我将Google Colab中的运行时类型更改为GPU,然后再次运行该模型。
并得到以下错误:
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-79-f43ade94ee10> in <module>()
5 epochs = 10,
6 use_multiprocessing=True,
----> 7 workers=2)

16 frames
/usr/local/lib/python3.6/dist-packages/imageio/core/request.py in _parse_uri(self, uri)
271 # Reading: check that the file exists (but is allowed a dir)
272 if not os.path.exists(fn):
--> 273 raise FileNotFoundError("No such file: '%s'" % fn)
274 else:
275 # Writing: check that the directory to write to does exist

FileNotFoundError: No such file: '/content/gdrive/My Drive/data/2017-IWT4S-CarsReId_LP-dataset/s01_l01/1_1.png'
今天,在不使用GPU的情况下运行程序时,我也遇到了此错误。运行该程序时,Colab告诉我Google Drive Time Out。那么,这是由于Google云端硬盘超时导致的错误吗?如果是,我该如何解决?
有人知道我应该在程序中更改什么吗?

最佳答案

您可以编写此代码以避免在控制台的google colab中超时

ConnectButton() {     
console.log("Connect pushed");
document.querySelector("#top-toolbar > colab-connect-
button").shadowRoot.querySelector("#connect").click()
}
setInterval(ConnectButton,60000);
资料来源: How to prevent Google Colab from disconnecting?

关于python - FileNotFoundError : No such file: -> Error occuring due to TimeOut of Google Drive?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62468830/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com