Google Colab is very slow compared to my PC : <p>I've recently started to use Google Colab, and wanted to train my first Convolutional NN. I imported the images from my Google Drive thanks to the answer I got <a href="https://stackoverflow.com/questions/49351071/load-image-dataset-folder-or-zip-located-in-google-drive-to-google-colab">here</a>.</p>

<p>Then I pasted my code to create the CNN into Colab and started the process.
Here is the complete code:</p>

<h2>Part 1: Setting up Colab to import picture from my Drive</h2>

<p>(part 1 is copied from <a href="https://stackoverflow.com/questions/49351071/load-image-dataset-folder-or-zip-located-in-google-drive-to-google-colab">here</a> as it worked as exptected for me</p>

<p>Step 1:</p>

<pre><code>!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2&gt;&amp;1 &gt; /dev/null
!apt-get update -qq 2&gt;&amp;1 &gt; /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
</code></pre>

<p>Step 2:</p>

<pre><code>from google.colab import auth
auth.authenticate_user()
</code></pre>

<p>Step 3:</p>

<pre><code>from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} &lt; /dev/null 2&gt;&amp;1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
</code></pre>

<p>Step 4:</p>

<pre><code>!mkdir -p drive
!google-drive-ocamlfuse drive
</code></pre>

<p>Step 5:</p>

<pre><code>print('Files in Drive:')
!ls drive/
</code></pre>

<h2>Part 2: Copy pasting my CNN</h2>

<p>I created this CNN with tutorials from a Udemy Course. It uses keras with tensorflow as backend.
For the sake of simplicity I uploaded a really simple version, which is plenty enough to show my problems</p>

<pre><code>from keras.models import Sequential
from keras.layers import Conv2D
from keras.layers import MaxPooling2D
from keras.layers import Flatten 
from keras.layers import Dense 
from keras.layers import Dropout
from keras.optimizers import Adam 
from keras.preprocessing.image import ImageDataGenerator 
</code></pre>

<p>parameters                                                                                                                                                         </p>

<pre><code>imageSize=32

batchSize=64

epochAmount=50
</code></pre>

<p>CNN                                                                                                                                                                </p>

<pre><code>classifier=Sequential() 

classifier.add(Conv2D(32, (3, 3), input_shape = (imageSize, imageSize, 3), activation = 'relu')) #convolutional layer

classifier.add(MaxPooling2D(pool_size = (2, 2))) #pooling layer

classifier.add(Flatten())
</code></pre>

<p>ANN                                                                                                                                                                </p>

<pre><code>classifier.add(Dense(units=64, activation='relu')) #hidden layer

classifier.add(Dense(units=1, activation='sigmoid')) #output layer

classifier.compile(optimizer = "adam", loss = 'binary_crossentropy', metrics = ['accuracy']) #training method
</code></pre>

<p>image preprocessing                                                                                                                                                </p>

<pre><code>train_datagen = ImageDataGenerator(rescale = 1./255,
                               shear_range = 0.2,
                               zoom_range = 0.2,
                               horizontal_flip = True)

test_datagen = ImageDataGenerator(rescale = 1./255) 

training_set = train_datagen.flow_from_directory('drive/School/sem-2-2018/BSP2/UdemyCourse/CNN/dataset/training_set',
                                             target_size = (imageSize, imageSize),
                                             batch_size = batchSize,
                                             class_mode = 'binary')

test_set = test_datagen.flow_from_directory('drive/School/sem-2-2018/BSP2/UdemyCourse/CNN/dataset/test_set',
                                        target_size = (imageSize, imageSize),
                                        batch_size = batchSize,
                                        class_mode = 'binary')

classifier.fit_generator(training_set,
                     steps_per_epoch = (8000//batchSize),
                     epochs = epochAmount,
                     validation_data = test_set,
                     validation_steps = (2000//batchSize))
</code></pre>

<h2>Now comes my Problem</h2>

<p>First of, the training set I used is a database with 10000 dog and cat pictures of various resolutions. (8000 training_set, 2000 test_set)</p>

<p>I ran this CNN on Google Colab (with GPU support enabled) and on my PC (tensorflow-gpu on GTX 1060)</p>

<p>This is an intermediate result from my PC:</p>

<pre><code>Epoch 2/50
63/125 [==============&gt;...............] - ETA: 2s - loss: 0.6382 - acc: 0.6520
</code></pre>

<p>And this from Colab:</p>

<pre><code>Epoch 1/50
13/125 [==&gt;...........................] - ETA: 1:00:51 - loss: 0.7265 - acc: 0.4916
</code></pre>

<p>Why is Google Colab so slow in my case? </p>

<p>Personally I suspect a bottleneck consisting of pulling and then reading the images from my Drive, but I don't know how to solve this other than choosing a different method to import the database.</p>
