【问题标题】:how to add a custom module in google colab?如何在 google colab 中添加自定义模块?
【发布时间】:2023-04-06 06:22:01
【问题描述】:
我想对数据进行训练,但它无法正常运行并显示模块错误:
"File "train.py", line 49, in <module>
from object_detection.builders import dataset_builder
ModuleNotFoundError: No module named 'object_detection'"
据我了解,由于此错误,无法运行对象检测文件夹中的自定义模块。这发生在以前。我以某种方式修复了它,但我不记得如何修复它。现在我尝试添加 pythonpath 或更改工作目录,但没有成功。谁能帮我解决这个问题?
【问题讨论】:
标签:
object
tensorflow
deep-learning
object-detection
google-colaboratory
【解决方案1】:
克隆 tensorflow 模型(如果你还没有)
%%bash
git clone https://github.com/tensorflow/models.git
然后,从 /tensorflow/models/research 目录运行以下命令:
!python setup.py build #builds the tensorflow models (this might take a while)
!python setup.py install #Install the models
!protoc object_detection/protos/*.proto --python_out=. #protobuf compilation
cd slim
!pip install -e . #install slim
cd .. #back to research direcotry
export PYTHONPATH=$PYTHONPATH:`pwd`:`pwd`/slim #set the path
!python object_detection/builders/model_builder_test.py #Test the object detection model(optional)
如果一切顺利,您将看到以下输出
在 0.152 秒内运行 22 次测试
好的(跳过=1)
那么您必须能够在没有此错误的情况下运行您的训练脚本。
注意:以防万一,如果您遇到与 protobuf 编译器相关的错误,请将版本 3.0.0 放入“tensorflow/models/research”目录,然后按照上述步骤操作。
wget -O protobuf.zip https://github.com/google/protobuf/releases/download/v3.0.0/protoc-3.0.0-linux-x86_64.zip
unzip protobuf.zip