اذهب إلى المحتوى

السؤال

نشر

أحاول استخدام الدالة to_categorical على غوغل كولاب لكن يظهر لي الخطأ التالي عندما أحاول استيرادها:

from keras.utils import to_categorical
y_train=to_categorical(y_train)
---------------------------------------------------------------------------

ImportError                               Traceback (most recent call last)

<ipython-input-1-812bfb11e6e7> in <module>()
----> 1 from keras.utils import to_categorical
	  2 y_train=to_categorical(y_train)

ImportError: cannot import name 'to_categorical' from 'keras.utils' (/usr/local/lib/python3.7/dist-packages/keras/utils/__init__.py)


---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

علماً أنني أقوم باستيرادها بنفس الشكل ضمن ال IDE على جهازي؟ما الحل؟

Recommended Posts

  • 2
نشر

تسطيع حل المشكلة بطريقتن فقط ضع قبل keras مكتبة tensorflow. مكتبة كيراس هي مثل واجهة أمامية ل tensorflow
يصبح الكود كالتالي:

from tensorflow.keras.utils import to_categorical
y_train=to_categorical(y_train)

الطريقه الثانيه هي أن to_categorical موجودة في الوحدة الوظيفة np_utils ضمن utils
وبتالي يصبح الكود:

from keras.utils.np_utils import to_categorical
y_train=to_categorical(y_train)

 

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...