0

python

from keras.layers import MaxPooling2D from keras.layers import Dense from Keras.layers import Flatten from keras.optimizers import SGD from keras.preprocessing.image import ImageDataGenerator def define_model(): model=Sequential() model.add(Conv2D(32,(3,3),activation='relu',kernel_intializer='he unifrom',padding='same',input_shape=(256,256,1))) model.add(MaxPooling2D((2,2))) model.add(Flatten()) model.add(Dense(128,activation='relu',kernel_intializer='he unifrom')) model.add(Dense(1,activation='sigmoid')) opt=SGD(lr=0.001,momentum=0.9) model.compile(optimizer=opt,loss='binary_crossentrophy',metrices=['accuracy']) return model def summarize_diagnostics(history): pyplot.subplot(211) pyplot.title('cross Entropy Loss') pyplot.plot(history.history['loss'],color='blue',label='train') pyplot.plot(history.history['val-acc'],color='orange',label='test') filename=sys.argv[0].split('/'[-1]) pyplot.savefig(filename+'-plot.png') pyplot.close() def run_test_harness(): model=define_model() datagen=ImageDataGenerator(rescale=1.0/255.0) train_it=datagen.flow_from_directory('dataset_dogs_vs_cats/train/',class_mode='binary',batch_size=64,target_size=(200,200)) test_it=datagen.flow_from_directory('dataset_dogs_vs_cats/test/',class_mode='binary',batch_size=64,target_size=(200,200)) history=model.flit_generator(train_it,steps_per_epoch=len(train_it),validation_data=test_it,validation_steps=len(test_it),epochs=20,verbose=0) _, acc=model.evaluate_generator(test_it,steps=len(test_it), verbose=0) print('> %.3f' % (acc * 100.0)) summarize_diagnostics(history) run_test_harness() bro....i run this program on anaconda spyder...the error is line 7, in <module> from Keras.layers import Flatten ModuleNotFoundError: No module named 'Keras'

12th Nov 2019, 6:57 AM
shahid afridi
shahid afridi - avatar
8 Respuestas
+ 1
Python is case sensitive. Write "keras" in lowercase. from keras.layers import Flatten
12th Nov 2019, 8:14 AM
Diego
Diego - avatar
+ 1
thanks sir diego
12th Nov 2019, 9:03 AM
shahid afridi
shahid afridi - avatar
0
experts please tell ..what i wrong with that program
12th Nov 2019, 7:05 AM
shahid afridi
shahid afridi - avatar
0
You need to install module named 'keras' through pip command.
12th Nov 2019, 7:23 AM
★«D.Connect_Zone»
★«D.Connect_Zone» - avatar
0
i had already instalI keras..then i check the version import theano print('theano: %s' % theano.__version__) # tensorflow import tensorflow print('tensorflow: %s' % tensorflow.__version__) # keras import keras print('keras: %s' % keras.__version__) the output is theano: 1.0.4 tensorflow: 2.0.0 keras: 2.3.1
12th Nov 2019, 7:30 AM
shahid afridi
shahid afridi - avatar
0
what i do next
12th Nov 2019, 7:31 AM
shahid afridi
shahid afridi - avatar
0
but sir..the output is not come...what's the problem
12th Nov 2019, 9:09 AM
shahid afridi
shahid afridi - avatar
0
Linge 3: change Keras to keras in: "from keras.layers import Flatten" And try again
13th Nov 2019, 12:40 PM
eco strophe
eco strophe - avatar