我正在使用Google Colab使用tensorflow对象检测api训练对象检测模型。当我运行单元格train.py
时,它会继续打印每一步的损失,最终在30分钟左右后,由于作为单元格输出打印的行数导致浏览器崩溃。
有没有可以用来定期清除输出(例如每30分钟)的脚本,而不是手动按一下?我正在使用Google Colab使用tensorflow对象检测API来训练对象检测模型。当我运行单元格train.py时,它会继续打印每一步的损失,最终在30分钟左右后,由于作为单元格输出打印的行数导致浏览器崩溃。
clear output button
?
答案 0 :(得分:2)
您可以使用google.colab.output.clear()
from google.colab import output
for i in range(100):
print(i)
# do something
if i%10 == 0:
output.clear()
答案 1 :(得分:1)
您好Jitesh Malipeddi,
因此,我遇到了与您同样的问题,尽管这不是最优雅的方法,但我提出了一个解决方法。我所做的是使用线程模块,并使用数组将一堆数字循环到数组中,并将我的output.clear()函数与模型训练一起使用。我今晚才想到这个,所以我将使用时间模块来开发一个更好的版本,因为这个版本是硬编码的。
from google.colab import output
import threading
#holds time in secs.
times = []
#this 6000 represents 100 mins
for y in range(6000):
#every 5mins
if y %300==0:
#append this number
times.append(y)
else:
continue
#this function holds are output.clear()
def gfg():
output.clear()
#for the length of the array times
for x in range(len(times)):
#start threading with the Timer module each element of the array
#and when times[x] arrives use function gfg to clear console.
timer = threading.Timer(times[x],gfg)
timer.start()
#your darknet training command
!./darknetdetectortrain
我的下一个版本将可以无限期继续,直到工作环境崩溃或您停止火车。仅供参考,如果您运行此脚本,并且想要更改时间以及清除清除输出脚本所需的时间,请重置运行时间,因为您将开始遇到问题。
答案 2 :(得分:0)
我实际上找到了解决此问题的方法。 在下面的行中将您要抑制输出的代码行括起来
from IPython.utils import io
with io.capture_output() as captured:
# Enter code here
在我的情况下,该单元格具有以下代码
from IPython.utils import io
with io.capture_output() as captured:
!python train.py --logtostderr --train_dir=/content/drive/My\ Drive/ocr_resized_train_checkpoints/ --pipeline_config_path=/content/frcnn_inception.config
我希望这对某人有帮助。如有任何问题,请通知我。
答案 3 :(得分:0)
%%capture
也可以
%%capture
!python train.py --logtostderr --train_dir=/content/drive/My\ Drive/ocr_resized_train_checkpoints/ --pipeline_config_path=/content/frcnn_inception.config
答案 4 :(得分:0)
这是部分解决方案,但您也可以在fit方法中将verbose
参数指定为0以获取无输出,或将参数2设置为减少输出。
您可以使用TensorBoard继续查看发生的情况。