EagerSession.ResourceCleanupStrategy
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
שולט כיצד מנקים משאבי TensorFlow כאשר אין בהם עוד צורך.
כל המשאבים שהוקצו במהלך EagerSession
נמחקים כאשר ההפעלה נסגרת. כדי למנוע שגיאות מחוץ לזיכרון, מומלץ גם לנקות את המשאבים הללו במהלך הפגישה. לדוגמה, ביצוע n פעולות בלולאה של מיטרציות יקצה מינימום של n*m משאבים בעוד שברוב המקרים, עדיין נעשה שימוש רק במשאבים מהאיטרציה האחרונה.
ניתן להודיע על מופעי EagerSession
בדרכים שונות כאשר אובייקטי TensorFlow אינם מופנים יותר, כך שהם יכולים להמשיך לניקוי כל המשאבים שבבעלותם.
שיטות בירושה
מכיתה java.lang.Enum int סופי | compareTo (E arg0) |
int | compareTo (Object arg0) |
בוליאנית סופית | שווה (Object arg0) |
מחלקה סופית<E> | getDeclaringClass () |
int סופי | hashcode () |
מחרוזת סופית | שם () |
int סופי | סידורי () |
חוּט | toString () |
סטטי <T מרחיב את Enum<T>> T | valueOf (Class<T> arg0, מחרוזת arg1) |
מכיתה java.lang.Object בוליאני | שווה (Object arg0) |
שיעור אחרון<?> | getClass () |
int | hashcode () |
ריק סופי | להודיע () |
ריק סופי | הודע הכל () |
חוּט | toString () |
ריק סופי | המתן (ארג0 ארוך, int arg1) |
ריק סופי | חכה (ארג0 ארוך) |
ריק סופי | חכה () |
מממשק java.lang.Comparable מופשט int | compareTo (E מרחיב את Enum<E> arg0) |
ערכים מנויים
ציבורי סטטי סופית EagerSession.ResourceCleanupStrategy IN_BACKGROUND
מעקב ומחק משאבים שאינם בשימוש משרשור חדש הפועל ברקע.
זוהי הגישה האמינה ביותר לניקוי משאבי TensorFlow, במחיר של התחלת והפעלת שרשור נוסף המוקדש למשימה זו. לכל מופע EagerSession
יש שרשור משלו, שנפסק רק כאשר ההפעלה סגורה.
אסטרטגיה זו משמשת כברירת מחדל.
סופי סטטי ציבורי EagerSession.ResourceCleanupStrategy ON_SAFE_POINTS
מעקב ומחק משאבים שאינם בשימוש משרשורים קיימים, לפני או אחרי שהם משלימים משימה אחרת.
משאבים שאינם בשימוש משתחררים כאשר קריאה לספריית TensorFlow מגיעה לנקודה בטוחה לניקוי. זה נעשה באופן סינכרוני ועלול לחסום לפרק זמן קצר את השרשור שהפעיל את השיחה.
יש להשתמש באסטרטגיה זו רק אם, מסיבות מסוימות, אין להקצות שרשור נוסף לניקוי. אחרת, יש להעדיף IN_BACKGROUND
.
ציבורי סטטי סופית EagerSession.ResourceCleanupStrategy ON_SESSION_CLOSE
מחק משאבים רק כאשר ההפעלה סגורה.
כל המשאבים שהוקצו במהלך הפגישה יישארו בזיכרון עד לסגירה מפורשת של הפגישה (או באמצעות טכניקת `נסה-עם-משאב` המסורתית). לא תבוצע ניסיון משימה נוספת לניקוי משאבים.
אסטרטגיה זו עלולה להוביל לשגיאות מחוץ לזיכרון והשימוש בה אינו מומלץ, אלא אם היקף הפגישה מוגבל לביצוע כמות קטנה של פעולות בלבד.
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים נוספים, אפשר לקרוא את מדיניות האתר של Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה. חלק מהתוכן הוא ברישיון NumPy.
עדכון אחרון: 2025-07-27 (שעון UTC).
[null,null,["עדכון אחרון: 2025-07-27 (שעון UTC)."],[],[],null,["# EagerSession.ResourceCleanupStrategy\n\npublic static final enum **EagerSession.ResourceCleanupStrategy** \nControls how TensorFlow resources are cleaned up when they are no longer needed.\n\nAll resources allocated during an `EagerSession` are deleted when the session is\nclosed. To prevent out-of-memory errors, it is also strongly suggest to cleanup those resources\nduring the session. For example, executing n operations in a loop of m iterations will allocate\na minimum of n\\*m resources while in most cases, only resources of the last iteration are still\nbeing used.\n\n`EagerSession` instances can be notified in different ways when TensorFlow objects are\nno longer being referred, so they can proceed to the cleanup of any resources they owned.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n### Inherited Methods\n\nFrom class java.lang.Enum \n\n|----------------------------------|---------------------------------------|\n| final int | compareTo(E arg0) |\n| int | compareTo(Object arg0) |\n| final boolean | equals(Object arg0) |\n| final Class\\\u003cE\\\u003e | getDeclaringClass() |\n| final int | hashCode() |\n| final String | name() |\n| final int | ordinal() |\n| String | toString() |\n| static \\\u003cT extends Enum\\\u003cT\\\u003e\\\u003e T | valueOf(Class\\\u003cT\\\u003e arg0, String arg1) |\n\nFrom class java.lang.Object \n\n|------------------|---------------------------|\n| boolean | equals(Object arg0) |\n| final Class\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| String | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nFrom interface java.lang.Comparable \n\n|--------------|-------------------------------------|\n| abstract int | compareTo(E extends Enum\\\u003cE\\\u003e arg0) |\n\nEnum Values\n-----------\n\n#### public static final EagerSession.ResourceCleanupStrategy\n**IN_BACKGROUND**\n\nMonitor and delete unused resources from a new thread running in background.\n\nThis is the most reliable approach to cleanup TensorFlow resources, at the cost of\nstarting and running an additional thread dedicated to this task. Each `EagerSession`\ninstance has its own thread, which is stopped only when the session is closed.\n\nThis strategy is used by default.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n#### public static final EagerSession.ResourceCleanupStrategy\n**ON_SAFE_POINTS**\n\nMonitor and delete unused resources from existing threads, before or after they complete\nanother task.\n\nUnused resources are released when a call to the TensorFlow library reaches a safe point\nfor cleanup. This is done synchronously and might block for a short period of time the thread\nwho triggered that call.\n\nThis strategy should be used only if, for some reasons, no additional thread should be\nallocated for cleanup. Otherwise, [IN_BACKGROUND](/versions/r2.13/api_docs/java/org/tensorflow/EagerSession.ResourceCleanupStrategy#IN_BACKGROUND) should be preferred.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n#### public static final EagerSession.ResourceCleanupStrategy\n**ON_SESSION_CLOSE**\n\nOnly delete resources when the session is closed.\n\nAll resources allocated during the session will remained in memory until the session is\nexplicitly closed (or via the traditional \\`try-with-resource\\` technique). No extra task for\nresource cleanup will be attempted.\n\nThis strategy can lead up to out-of-memory errors and its usage is not recommended, unless\nthe scope of the session is limited to execute only a small amount of operations.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]