Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
150 views
in Technique[技术] by (71.8m points)

python - Dataset with jpg import to jupyter notebook

I've to build a machine learning model with python via jupyter notebook using tensorflow and keras. I've a Dataset of 1000 pictures. 800 of them I want to use for training the model and the 200 for testing and validation. It is for a gender and age prediction model. Now how do I import my dataset or how do I write the path in upyter notebook or google colab to import my Dataset.

What I've done is imported the packages for my project.

from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.preprocessing.image import img_to_array
from tensorflow.keras.utils import to_categorical, plot_model
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import BatchNormalization, Conv2D, MaxPooling2D, Activation, Flatten, Dropout, Dense
from tensorflow.keras import backend as K
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
import numpy as np
import random
import cv2
import os
import glob
import pandas as pd

Kind regards.

question from:https://stackoverflow.com/questions/65645275/dataset-with-jpg-import-to-jupyter-notebook

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There are two ways you can upload the dataset in google colab, if the dataset is in your local system.

  1. You can upload your dataset to your Google drive.

And the simplest way to share files is to mount your Google Drive in your Google Colab notebook.

To do this, run the following in a code cell:

from google.colab import drive
drive.mount('/content/drive')

It will ask you to visit a link to ALLOW "Google Files Stream" to access your drive. After that, a long alphanumeric auth code will be shown that needs to be entered in your Colab's notebook.

Afterward, your Drive files will be mounted and you can browse them with the file browser in the side panel.

  1. You can upload files manually by browsing to your local file system

It takes a longer time to upload in this method.

from google.colab import files
uploaded = files.upload()

Here are two examples for your reference:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...