如何在训练集中为每个迭代的每个迭代打印输出数组?

时间:2019-12-27 17:05:02

标签: python-3.x tensorflow deep-learning classification

我需要在每个时期打印输出数组(Y hat),我该怎么做? 这是我现有的带4个输出的conv-net代码,数据生成器,模型配置等。 我想为每次迭代打印输出数组。

     img_rows = 150    
     img_cols = 150   
     epochs = 30    
     batch_size = 32    
     num_of_train_samples = 800    
     num_of_test_samples = 200    
     #Image Generator    
     train_datagen = ImageDataGenerator(rescale=1. / 255,  
                                        rotation_range=40,
                                        width_shift_range=0.2,
                                        height_shift_range=0.2,
                                        shear_range=0.2,
                                        zoom_range=0.2,
                                        horizontal_flip=True,
                                        fill_mode='nearest')     
     test_datagen = ImageDataGenerator(rescale=1. / 255)    
     train_generator = train_datagen.flow_from_directory(train_data_path,
                       target_size=(img_rows, img_cols),
                       batch_size=batch_size,
                       class_mode='categorical')   
     test_generator = test_datagen.flow_from_directory(test_data_path,
                       target_size=(img_rows, img_cols),
                       batch_size=batch_size,
                       class_mode='categorical')  
     validation_generator = test_datagen.flow_from_directory(val_data_path,
                            target_size=(img_rows, img_cols),
                            batch_size=batch_size,
                            class_mode='categorical')  
     # Build model    
     model = Sequential()  
     model.add(Convolution2D(32, (3, 3), input_shape=(img_rows, img_cols, 
       3), padding='valid'))   
     model.add(Activation('relu'))  
     model.add(MaxPooling2D(pool_size=(2, 2)))  
     model.add(Convolution2D(32, (3, 3), padding='valid'))  
     model.add(Activation('relu'))  
     model.add(MaxPooling2D(pool_size=(2, 2)))  
     model.add(Convolution2D(64, (3, 3), padding='valid'))  
     model.add(Activation('relu'))  
     model.add(MaxPooling2D(pool_size=(2, 2)))  
     model.add(Flatten())  
     model.add(Dense(64))  
     model.add(Activation('relu'))  
     model.add(Dropout(0.5))  
     model.add(Dense(4))  
     model.add(Activation('softmax'))  
     model.compile(loss='categorical_crossentropy',
                   optimizer='rmsprop',
                   metrics=['accuracy'])  
     #Train  
     history=model.fit_generator(train_generator,
                             steps_per_epoch=num_of_train_samples // 
                               batch_size,
                             epochs=epochs,
                             validation_data=validation_generator,
                             validation_steps=num_of_test_samples // 
                               batch_size)

0 个答案:

没有答案