개요
TensorFlow는 Google Brain 팀이 처음 개발한 오픈 소스 엔드투엔드 머신러닝 플랫폼입니다. 유연한 도구와 라이브러리 생태계를 제공하며, 안정적인 Python 및 C++ API를 갖추고 있고, CPU, GPU 및 분산 환경에서 연구와 프로덕션 배포를 지원합니다.
README 미리보기
\n \n\n\n[](https://badge.fury.io/py/tensorflow)\n[](https://badge.fury.io/py/tensorflow)\n[](https://doi.org/10.5281/zenodo.4724125)\n[](https://bestpractices.coreinfrastructure.org/projects/1486)\n[](https://securityscorecards.dev/viewer/?uri=github.com/tensorflow/tensorflow)\n[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:tensorflow)\n[](https://bugs.chromium.org/p/oss-fuzz/issues/list?sort=-opened&can=1&q=proj:tensorflow-py)\n[](https://ossrank.com/p/44)\n[](CODE_OF_CONDUCT.md)\n\n**`Documentation`** |\n------------------- |\n[](https://www.tensorflow.org/api_docs/) |\n\n[TensorFlow](https://www.tensorflow.org/) is an end-to-end open source platform\nfor machine learning. It has a comprehensive, flexible ecosystem of\n[tools](https://www.tensorflow.org/resources/tools),\n[libraries](https://www.tensorflow.org/resources/libraries-extensions), and\n[community](https://www.tensorflow.org/community) resources that lets\nresearchers push the state-of-the-art in ML and developers easily build and\ndeploy ML-powered applications.\n\nTensorFlow was originally developed by researchers and engineers working within\nthe Machine Intelligence team at Google Brain to conduct research in machine\nlearning and neural networks. However, the framework is versatile enough to be\nused in other areas as well.\n\nTensorFlow provides stable [Python](https://www.tensorflow.org/api_docs/python)\nand [C++](https://www.tensorflow.org/api_docs/cc) APIs, as well as a\nnon-guaranteed backward compatible API for\n[other languages](https://www.tensorflow.org/api_docs).\n\nKeep up-to-date with release announcements and security updates by subscribing\nto\n[announce@tensorflow.org](https://groups.google.com/a/tensorflow.org/forum/#!forum/announce).\nSee all the [mailing lists](https://www.tensorflow.org/community/forums).\n\n## Install\n\nSee the [TensorFlow install guide](https://www.tensorflow.org/install) for the\n[pip package](https://www.tensorflow.org/instal
FAQ (5)
문제 해결float16 입력으로 tf.image.non_max_suppression을 사용할 때 발생하는 XLA 컴파일 오류 'Seen floating point types of different precisions, mixed precision is disallowed'를 수정하는 방법은 무엇입니까?
이것은 TensorFlow 버그입니다: tf.image.non_max_suppression는 iou_threshold/score_threshold를 Python float(float32)로 전달하므로, float16 boxes/scores와 함께 사용하면 op가 T=float16, T_threshold=float32로 실행되며, 이는 tf.function(jit_compile=True) 하에서 XLA가 컴파일 시점에 거부합니다.
**우회 방법:** tf.raw_ops.NonMaxSuppressionV3를 직접 호출하고 threshold를 float16으로 캐스팅하여 T == T_threshold가 되도록 하세요:
def nms_f16(boxes, scores):
return tf.raw_ops.NonMaxSuppressionV3(
boxes=boxes, scores=scores, max_output_size=2,
iou_threshold=tf.constant(0.3, tf.float16),
score_threshold=tf.constant(float('-inf'), tf.float16))
tf.function(nms_f16, jit_compile=True)(boxes, scores) # compiles, returns [0 1]
**대안:**
- tf.image.non_max_suppression를 호출하기 전에 boxes/scores를 float32로 캐스팅한 다음, 필요한 경우 결과를 다시 캐스팅하세요.
- eager 모드는 혼합된 dtype을 올바르게 처리하므로, (jit_compile=True 없이) op를 eager로 실행하세요.
tf-nightly 2.23.0-dev(CPU, 디바이스 독립적)에서 확인되었습니다. 업스트림 수정 사항은 tensorflow/tensorflow#128614에서 추적하세요.
문제 해결왜 tf.subtract(5, float_tensor)는 eager 모드에서는 작동하지만 tf.function이나 XLA 내부에서는 'TypeError: type float32 does not match type int32' 오류가 발생하며 실패하나요?
알려진 TensorFlow 버그 (nightly 2.22.0-dev, issue #127911): PR #125387에서 tf.multiply/tf.pow/tf.divide에 Python 스칼라 dtype 강제 변환(coercion)을 추가했지만 tf.subtract는 누락되었습니다. 이로 인해 eager 모드에서는 Python int를 텐서의 float32 dtype으로 강제 변환하는 반면, 그래프 모드와 XLA (jit_compile=True)에서는 int32로 변환하여 Sub(int32, float32) 불일치가 발생합니다. 수정이 적용될 때까지의 해결 방법: 모든 실행 모드가 일치하도록 스칼라를 명시적으로 변환하세요 — tf.subtract(tf.cast(5, t.dtype), t) 또는 tf.subtract(tf.constant(5, dtype=t.dtype), t). tf.function 내부에서 tf.subtract에 순수 Python 스칼라를 전달하지 마세요. 커스텀 빌드의 경우, multiply()에서 사용된 것과 동일한 강제 변환을 subtract()에 추가하여 tensorflow/python/ops/math_ops.py를 패치하세요: if not tensor_util.is_tf_type(x) and tensor_util.is_tf_type(y): x = ops.convert_to_tensor(x, dtype=y.dtype.base_dtype, name='x').
문제 해결TensorFlow에서 'Protobuf gencode version 5.28.3 is exactly one major version older than the runtime version' 경고를 해결하는 방법은?
이 경고는 TensorFlow 2.20이 protobuf gencode 5.28.3으로 컴파일되었지만, pip이 더 최신 버전인 protobuf 런타임 6.x(예: 6.31.1)를 설치했기 때문에 나타납니다. gencode 메이저 버전과 일치하도록 protobuf Python 패키지를 다운그레이드하여 해결하세요:
pip install "protobuf<6.0"
또는 정확한 버전을 고정하세요:
pip install protobuf==5.28.3
Pipenv/Pipfile을 사용하는 경우, protobuf는 TensorFlow의 전이적 의존성으로 설치되므로 Pipfile에 protobuf = "<6.0"을 명시적으로 추가하고 pipenv install을 실행하세요. 또는 다운그레이드하지 않고 경고를 없애려면 코드에서 경고를 억제하세요:
import warnings
warnings.filterwarnings("ignore", message="Protobuf gencode version")
gencode/런타임 불일치는 향후 런타임 릴리스에서 호환성 위반을 일으킬 수 있으므로 다운그레이드가 권장되는 해결 방법입니다.
문제 해결tf.signal.kaiser_bessel_derived_window가 window_length보다 적은 샘플을 반환하는 이유는 무엇인가요?
이는 알려진 버그입니다: 홀수 window_length 값의 경우, 구현에서 각각 window_length // 2 개의 샘플로 구성된 두 개의 절반을 만들기 때문에 출력에는 window_length - 1 개의 샘플이 포함됩니다(예: window_length=5는 shape (4,)를 반환하고, window_length=1은 빈 텐서를 반환합니다). 해결 방법: Kaiser-Bessel Derived (KBD) 윈도우는 수학적으로 짝수 길이에 대해서만 정의되므로 짝수 윈도우 길이만 전달하세요. 윈도우를 신호 프레임과 짝지을 때 다운스트림 shape 불일치를 방지하려면, 호출하기 전에 홀수 길이를 가장 가까운 짝수로 반올림하세요(예: n += n % 2).
문제 해결tf.function 내부에서 window_length=1일 때 tf.signal.kaiser_window가 [nan]을 반환하는 이유는 무엇인가요?
이는 알려진 TensorFlow 버그입니다(tensorflow/tensorflow#129234, tf-nightly 2.23.0-dev에서 확인됨). kaiser_window는 길이가 정적 Python 상수일 때만 길이 1을 특수 케이스로 처리합니다. window_length가 동적 텐서인 경우(예: tf.function 인수), 내부 halflen_float가 0이 되고, arg / halflen_float 표현식이 0/0으로 평가되어, 결과가 [1.] 대신 [nan]이 됩니다. 우회 방법: tf.cond를 사용해 길이 1 케이스를 직접 가드하세요. 예: tf.cond(tf.equal(n, 1), lambda: tf.ones([1], dtype=tf.float32), lambda: tf.signal.kaiser_window(n, beta=beta)). 또는 eager 모드와 np.kaiser(1, beta)가 모두 [1.]을 올바르게 반환하므로, n=1인 경우 eager 모드에서 윈도우를 계산할 수도 있습니다. hann_window와 hamming_window는 이미 window_length == 1에 대한 내부 cond를 통해 이 케이스를 올바르게 처리하므로, 수정 사항이 반영될 때까지 참조 동작으로 사용할 수 있습니다.