기억 저장소

클라우드 기반 인공지능 개발과 DevOps 실무

인공지능/텐서 플로우

텐서플로우: TensorFlow Object Detection 설치 / 환경구축하기 환경만드는 방법,환경시작하기,처음부터 끝까지 완벽정리

하늘.98 2021. 12. 29. 18:15

TFOD를 사용하기 위한 환경설정

 

!!!!!!!!!!!!!!!! 사이트에 가이드라인만 따라하면 된다.

TensorFlow Object Detection 공식사이트(가이드 라인):

https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/latest/install.html

 

Installation — TensorFlow 2 Object Detection API tutorial documentation

Anaconda Python 3.8 (Optional) Although having Anaconda is not a requirement in order to install and use TensorFlow, I suggest doing so, due to it’s intuitive way of managing packages and setting up new virtual environments. Anaconda is a pretty useful t

tensorflow-object-detection-api-tutorial.readthedocs.io

 

 

 

1111111111111111111111111111. 가상환경 설정 및 텐서플로우 설치

 

$ conda create -n tfod python=3.9

$ conda activate tfod

$ pip install tensorflow==2.2.0

$ python

$ import tensorflow as tf

 

base 에서 가상환경이름 tensorflow 로  가상환경이 구축 되었다.

 

 

 

 

2222222222222222222222222222222.텐서 플로우 설치하기 

pip install --ignore-installed --upgrade tensorflow==2.5.0

----------------------잘깔렸는지 확인해보는 코드 -----------------------------------

python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

 

 

 

 

 

333333333333333333333333333333333.

models 다운 및 tensorflow 폴더만들어주기

 

 

https://github.com/tensorflow/models

 

GitHub - tensorflow/models: Models and examples built with TensorFlow

Models and examples built with TensorFlow. Contribute to tensorflow/models development by creating an account on GitHub.

github.com

위에 models 를 다운 받아 준 뒤 

내문서에 tensorflow 라는 폴더를 만들어 준뒤

다운로드한 폴더이름을 models 라고 바꿔서 tensorflow 폴더에 넣어준다,

 

 

44444444444444444444444444444444444.

아래의 코드를 사용하기 전 !!! 환경변수를 만들어 준 뒤 코드를 사용해준다.

자신의 로컬 컴퓨터와 맞는 Protobuf 를 다운해 주면 된다 .

protoc object_detection/protos/*.proto --python_out=.

https://github.com/protocolbuffers/protobuf/releases

 

Releases · protocolbuffers/protobuf

Protocol Buffers - Google's data interchange format - protocolbuffers/protobuf

github.com

 

 

1. 압축해제

2. C:\Program Files로 이동

3. Google protobuf폴더 만들기

4. 압축 푼 파일 모두 옮겨놓기

5. 환경변수 설정 : User Path에 위 경로 Google Protobuf/bin을 추가. (내 컴퓨터 -마우스 우클릭 -속성 -고급시스템 설정 -환경변수 -사용자 변수의 path 편집 C:\Program Files\Google Protobuf\bin입력. -시스템 변수의 path에도 편집후 동일하게 C:\Program Files\Google Protobuf\bin입력.)

 

(압축 풀기한 폴더를 아래의 Google protobuf에 넣어준다.

 

 

C:\Program Files\Google Protobuf\bin 의 경로는  파일탐색기에서 bin 까지 들어간 경로를 복사 붙여넣기 하면된다.

 

 

 

 

 

55555555555555555555555555 . coco api 를 다운해준다.

pip install cython
pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI

수동 설치 경로(pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI)

 

 

 

 

6666666666666666666666666. object detection API 

주의사항!!!!!!!

 

cp object_detection/packages/tf2/setup.py .

주의사항!!!!!!!

윈도우에서는 cp object_detection/packages/tf2/setup.py .  가 안되기 때문에  파워 셀에 입력해준다.

 

터미널에 입력해준다. (코랩에 사용시에는 python -m pip install .     만 입력해준다.)

python -m pip install --use-feature=2020-resolver .

Test your Installation  (잘 다운 되었는지 테스트 해본다.) 

python object_detection/builders/model_builder_tf2_test.py

설치완료!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 

 

 

 

 

 

777777777777777777777777777. github에 새로운 프로젝트(레파지토리) 를 만든 뒤 clone 해준다. 

 

 

(저는 비주얼 스튜디오를 사용했습니다.) 비주얼 스튜디오를 열어 준 뒤 왼쪽아래 

빨간 테두리 표시된 부분을 눌러준 뒤 내가 만든 가상환경으로 들어가준다.

(tensorflow2 -> 제가 만든 가상환경 이름입니다.)

Tensorflow\models\research                               시작 환경이여야 함 

 

streamlit 을 이용하고 싶은경우에는 

pip install streamlit  

을 사용 한뒤 다시 시작해주면 된다. 

 

 

 

 

 

-----------------------------------------------------------------------------------------------------------------------------------

 

 

 

 

 reserch 폴더에 objection detection 폴더 내부에 models 폴더를 보면 많은 모델들이 존재한다.

(다운로드 해준다)

https://github.com/tensorflow/models/tree/master/research/object_detection

 

 

3. Protobuf 설치(라이브러리)

자신의 로컬 컴퓨터와 맞는 Protobuf 를 다운해 주면 된다 .

 

공식 깃허브 : https://github.com/protocolbuffers/protobuf 

 

GitHub - protocolbuffers/protobuf: Protocol Buffers - Google's data interchange format

Protocol Buffers - Google's data interchange format - GitHub - protocolbuffers/protobuf: Protocol Buffers - Google's data interchange format

github.com

 

 

 

 

 

ex) coco api 사이트 

https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI

 

주피터 사용하고싶은 경우 

# model/research/object_detection 에서 실행

$ jupyter notebook 

(비주얼 스튜디오에서 안될 경우 아나콘다 프롬포트에서 사용해보자)