In the test to analyze the effect of the IDE, in the Pycharm test when the teacher prompted memory overflow, and run Autokeras CNN really consumes a lot of space. But on the same computer, there is no problem when you change the Vscode for testing. I don't know what's going on. Recommended if the computer running memory is not 12G recommended don't run. It's a good idea to use Vscode. This IDE performs relatively efficiently. And there are few problems. The only certainty is that writing code is inefficient. You can also write code in Pycharm and put it in Vscode to perform the test.
Test data download Link: Https://pan.baidu.com/s/16a1PN3L-lYy-61Wfjvd1VQ Password: 3UBR
Test code:
# coding: utf-8
import os
os.environ [‘TF_CPP_MIN_LOG_LEVEL’] = ‘2’
import numpy as np
import matplotlib.pyplot as plt
from scipy.misc import imresize
import cv2
from autokeras.image_supervised import ImageClassifier
from sklearn.metrics import accuracy_score
from keras.models import load_model
from keras.utils import plot_model
Import time
start = time.time ()
def read_img (path, class_num):
imgName_list = os.listdir (path)
n = len (imgName_list)
# img_index, img_colummns, img_rgbSize = plt.imread (path + ‘/‘ + imgName_list [0]). shape
img_index, img_colummns = [28,38] # This setting is important. If your computer is good, you can ignore the settings. Otherwise there is not enough memory.
print (img_index, img_colummns)
data = np.zeros ([n, img_index, img_colummns, 1])
label = np.zeros ([n, 1])
class_number = 0
for i in range (n):
imgPath = path + ‘/‘ + imgName_list [i]
data [i,:,:, 0] = imresize (cv2.cvtColor (plt.imread (imgPath), cv2.COLOR_BGR2GRAY), [img_index, img_colummns])
if (i)% (class_num) == 0:
class_number = class_number + 1
label [i, 0] = class_number
return data, label
x_train, y_train = read_img (‘./ data / re / train’, 80)
x_test, y_test = read_img (‘./ data / re / test’, 20)
animal = [‘bus’, ‘dinosaur’, ‘flower’, ‘horse’, ‘elephant’] # corresponding to animal category labelValue is [1,2,3,4,5]
# plt.imshow (x_test [0,:,:, 0], cmap = ‘gray’)
# plt.show ()
if __name __ == ‘__ main__’:
# Model building
model = ImageClassifier (verbose = True)
# Search network model
model.fit (x_train, y_train, time_limit = 1 * 60)
# Verify the optimal model
model.final_fit (x_train, y_train, x_test, y_test, retrain = True)
# Give evaluation results
score = model.evaluate (x_test, y_test)
# Recognition results
y_predict = model.predict (x_test)
# Accuracy
accuracy = accuracy_score (y_test, y_predict)
# Print out score and accuracy
print (‘score:‘, score, ‘accuracy:‘, accuracy)
model_dir = r ‘./ modelStructure / imgModel.h5’
model_img = r ‘./ modelStructure / imgModel_ST.png’
# Save the visualization model
# model.load_searcher (). load_best_model (). produce_keras_model (). save (model_dir)
# Load the model
# automodel = load_model (model_dir)
# Output model structure
# plot_model (automodel, to_file = model_img)
end = time.time ()
print (end-start)
Getting Started testing for Autokeras Windows