在训练10,000个手写字符的图像数据库期间,我在Goggle合作实验室中遇到了速度慢的问题

时间:2019-09-21 08:02:44

标签: jupyter-notebook google-colaboratory kaggle

在训练10,000个手写字符的图像数据库期间,我在Goggle colab中面临缓慢。我在kaggle上进行了类似的培训,其中每个纪元都花了84秒,而在谷歌合作实验室中,每个纪元花费了超过350秒。代码类似..

  from google.colab import drive
# This will prompt for authorization.
    drive.mount('/content/drive')
    import numpy as np
    import keras
    from keras import backend as k
    from keras.models import Sequential
    from keras.layers import Activation
    from keras.layers.core import Dense,Flatten
    from keras.optimizers import Adam
    from keras.metrics import categorical_crossentropy
    from keras.preprocessing.image import ImageDataGenerator
    from keras.layers.normalization import BatchNormalization
    from keras.layers.convolutional import *
    from matplotlib import pyplot as plt
    from sklearn.metrics import confusion_matrix
    import itertools
    import matplotlib.pyplot as plt
    %matplotlib inline
    from keras.models import Model
    from keras.preprocessing import image
    from keras.applications import imagenet_utils
    from keras.applications.resnet import preprocess_input
    from keras.preprocessing import image
    from keras.models import Model
    from keras.models import model_from_json
    from keras.layers import Input

    train_path='/content/only_jukto/train' 
    valid_path='/content/only_jukto/valid'
    test_path='/content/only_jukto/test'

    train_batches=ImageDataGenerator(preprocessing_function=keras.applications.resnet50.preprocess_input).flow_from_directory(train_path,target_size=(224,224),batch_size=32)
    valid_batches= ImageDataGenerator(preprocessing_function=keras.applications.resnet50.preprocess_input).flow_from_directory(valid_path,target_size=(224,224),batch_size=32)
    test_batches= ImageDataGenerator(preprocessing_function=keras.applications.resnet50.preprocess_input).flow_from_directory(test_path,target_size=(224,224),batch_size=32)
    mobile = keras.applications.resnet.ResNet50(include_top=True, weights='imagenet', input_tensor=None, input_shape=None, pooling=None, classes=1000)

    x = mobile.layers[-2].output
    predictions = Dense(52,activation='softmax')(x)
    model = Model(inputs=mobile.input,outputs=predictions)

    model.summary()

    model.compile(Adam(lr=0.001),loss='categorical_crossentropy',metrics=['accuracy'])
    model.fit_generator(train_batches,steps_per_epoch=337,validation_data=valid_batches,validation_steps = 113,epochs = 30 , verbose=1) 

这是代码...我也面临着一些我在kaggle内核中找不到的贬损警告。有人可以帮我吗?

0 个答案:

没有答案