В Colab Laboratory, в Python3, я включил тип времени выполнения Runtime-Change для GPU
Тогда я сделал этот код:
import pandas as pd
import numpy as np
# Code to read csv file into Colaboratory:
!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
# Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
#Link of a 10GB file in Google Drive
link = ''
fluff, id = link.split('=')
print (id) # Verify that you have everything after '='
downloaded = drive.CreateFile({'id':id})
downloaded.GetContentFile('empresa.csv')
Но я не могу открыть файл из-за нехватки памяти: ваш сеанс потерпел крах после использования всей доступной оперативной памяти
У меня есть:
Подключено к «Python 3 Google Compute Engine (GPU)»
Оперативная память: 0,64 ГБ / 12,72 ГБ Диск: 25,14 ГБ / 358,27 ГБ
Пожалуйста, есть ли способ увеличить ОЗУ в колаборатории?
бесплатно или платно
- / -
Я пробовал альтернативным способом, подключив диск как файловую систему
from google.colab import drive
drive.mount('/content/gdrive')
with open('/content/gdrive/My Drive/foo.txt', 'w') as f:
f.write('Hello Google Drive!')
!cat /content/gdrive/My\ Drive/foo.txt
# Drive REST API
from google.colab import auth
auth.authenticate_user()
# Construct a Drive API client
from googleapiclient.discovery import build
drive_service = build('drive', 'v3')
# Downloading data from a Drive file into Python
file_id = ''
import io
from googleapiclient.http import MediaIoBaseDownload
request = drive_service.files().get_media(fileId=file_id)
downloaded = io.BytesIO()
downloader = MediaIoBaseDownload(downloaded, request)
done = False
while done is False:
# _ is a placeholder for a progress object that we ignore.
# (Our file is small, so we skip reporting progress.)
_, done = downloader.next_chunk()
downloaded.seek(0)
print('Downloaded file contents are: {}'.format(downloaded.read()))
Но проблема сохраняется: ваш сеанс потерпел крах после использования всей доступной оперативной памяти