首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FileNotFoundError:没有这样的文件:由于Google Drive的TimeOut而发生->错误?

问FileNotFoundError:没有这样的文件:由于Google Drive的TimeOut而发生->错误?
EN

Stack Overflow用户
提问于 2020-06-19 19:00:30
回答 2查看 249关注 0票数 1

我创建了一个DataGenerator with Sequence类。

代码语言:javascript
复制
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是训练数据的一个主编码标签。验证数据也是如此。

我使用以下代码创建了图像路径:

代码语言:javascript
复制
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应用于训练和验证数据:

代码语言:javascript
复制
training_generator = DataGenerator(X_train, y_train, batch_size=32)
validation_generator = DataGenerator(X_val, y_val, batch_size=32)

之后,我使用fit_generator方法运行了一个模型:

代码语言:javascript
复制
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,并再次运行该模型。

并得到以下错误:

代码语言:javascript
复制
---------------------------------------------------------------------------
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超时。那么,这个错误是由于Google Drive的超时造成的吗?如果是,我该如何解决这个问题呢?有人知道我应该在程序中修改什么吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-06-27 20:23:37

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

代码语言:javascript
复制
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?

票数 1
EN

Stack Overflow用户

发布于 2020-06-20 02:18:31

问题似乎出在输入上。您的模型找不到输入文件。如果你改变了运行时,那么将会有一个出厂重置。会话中的所有磁盘内容都将被擦除。

如果在两者之间更改运行时,请从头开始运行单元格。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62468830

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档