且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

tensorflow gpu仅在CPU上运行

更新时间:2022-03-15 00:02:49

@Smokrow,谢谢您以上的回答. 在Windows平台上,Keras似乎在多处理方面遇到了问题.

@Smokrow, thank you for your answers above. It appears to be the case that Keras seems to have problems with multiprocessing in Windows platforms.

history = merged_model.fit_generator(generator=train_generator,
                                     epochs=60,
                                     verbose=2,
                                     callbacks=[reduce_lr_on_plateau],
                                     validation_data=val_generator,
                                     use_multiprocessing=True,
                                     max_queue_size=50,
                                     workers=3)

以上代码段导致Keras挂起,实际上看不到进度.如果用户在Windows上运行其代码,则use_multiprocessor需要设置为False!否则,它将不起作用. 有趣的是,仍然可以将worker设置为大于1的数字,并且仍然可以提高性能.我很难理解后台实际发生的情况,但是确实可以提高性能.因此,下面的代码使它可以工作.

The piece of code above causes the Keras to hang and literally no progress is seen. If the user is runing his/her code on Windows, use_multiprocessor needs to be set to False! Otherwise, it does not work. Interestingly, workers can still be set to a number that is greater than one and it still gives performance benefits. I am having difficulties to understand what really is happening in the background but it does give performance improvement. So the following piece of code made it work.

history = merged_model.fit_generator(generator=train_generator,
                                     epochs=60,
                                     verbose=2,
                                     callbacks=[reduce_lr_on_plateau],
                                     validation_data=val_generator,
                                     use_multiprocessing=False,  # CHANGED
                                     max_queue_size=50,
                                     workers=3)