深度學(xué)習(xí)Course 2踩坑記

? Deep learning by Andrew NG在Course2的作業(yè)挺多坑的轨帜,可能是當(dāng)時(shí)他布置作業(yè)時(shí)的環(huán)境比較舊皮假,而現(xiàn)在搭建的Anaconda環(huán)境相對較新鞋拟,有些方法已經(jīng)不適用而造成的的。

先完成Regularizaion的作業(yè)惹资,運(yùn)行

\COURSE 2 Improving Deep Neural Networks Hyperparameter tuning, Regularization and Optimization\week5\Regularization\Regularization.ipynb

第一坑:

首先踩到的第一個坑是如下提示:

train_X, train_Y, test_X, test_Y = load_2D_dataset()

TypeError? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Traceback (most recent call last)

d:\Anaconda3\lib\site-packages\matplotlib\colors.py in to_rgba(c, alpha)

? ? 173? ? try:

--> 174? ? ? ? rgba = _colors_full_map.cache[c, alpha]

? ? 175? ? except (KeyError, TypeError):? # Not in cache, or unhashable.

TypeError: unhashable type: 'numpy.ndarray'

During handling of the above exception, another exception occurred:

ValueError? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Traceback (most recent call last)

d:\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)

? 4231? ? ? ? ? ? try:? # Then is 'c' acceptable as PathCollection facecolors?

-> 4232? ? ? ? ? ? ? ? colors = mcolors.to_rgba_array(c)

? 4233? ? ? ? ? ? ? ? n_elem = colors.shape[0]

d:\Anaconda3\lib\site-packages\matplotlib\colors.py in to_rgba_array(c, alpha)

? ? 274? ? for i, cc in enumerate(c):

--> 275? ? ? ? result[i] = to_rgba(cc, alpha)

? ? 276? ? return result

d:\Anaconda3\lib\site-packages\matplotlib\colors.py in to_rgba(c, alpha)

? ? 175? ? except (KeyError, TypeError):? # Not in cache, or unhashable.

--> 176? ? ? ? rgba = _to_rgba_no_colorcycle(c, alpha)

? ? 177? ? ? ? try:

d:\Anaconda3\lib\site-packages\matplotlib\colors.py in _to_rgba_no_colorcycle(c, alpha)

? ? 230? ? if len(c) not in [3, 4]:

--> 231? ? ? ? raise ValueError("RGBA sequence should have length 3 or 4")

? ? 232? ? if len(c) == 3 and alpha is None:

ValueError: RGBA sequence should have length 3 or 4

During handling of the above exception, another exception occurred:

ValueError? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Traceback (most recent call last)

<ipython-input-5-a9a84d38b990> in <module>

----> 1 train_X, train_Y, test_X, test_Y = load_2D_dataset()

~\Desktop\COURSE 2 Improving Deep Neural Networks Hyperparameter tuning, Regularization and Optimization\week5\Regularization\reg_utils.py in load_2D_dataset()

? ? 332? ? test_Y = data['yval'].T

? ? 333

--> 334? ? plt.scatter(train_X[0, :], train_X[1, :], c=train_Y, s=40, cmap=plt.cm.Spectral);

? ? 335

? ? 336? ? return train_X, train_Y, test_X, test_Y

d:\Anaconda3\lib\site-packages\matplotlib\pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, data, **kwargs)

? 2860? ? ? ? vmin=vmin, vmax=vmax, alpha=alpha, linewidths=linewidths,

? 2861? ? ? ? verts=verts, edgecolors=edgecolors, **({"data": data} if data

-> 2862? ? ? ? is not None else {}), **kwargs)

? 2863? ? sci(__ret)

? 2864? ? return __ret

d:\Anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, data, *args, **kwargs)

? 1808? ? ? ? ? ? ? ? ? ? ? ? "the Matplotlib list!)" % (label_namer, func.__name__),

? 1809? ? ? ? ? ? ? ? ? ? ? ? RuntimeWarning, stacklevel=2)

-> 1810? ? ? ? ? ? return func(ax, *args, **kwargs)

? 1811

? 1812? ? ? ? inner.__doc__ = _add_data_doc(inner.__doc__,

d:\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)

? 4243? ? ? ? ? ? ? ? ? ? ? ? "acceptable for use with 'x' with size {xs}, "

? 4244? ? ? ? ? ? ? ? ? ? ? ? "'y' with size {ys}."

-> 4245? ? ? ? ? ? ? ? ? ? ? ? .format(nc=n_elem, xs=x.size, ys=y.size)

? 4246? ? ? ? ? ? ? ? ? ? )

? 4247? ? ? ? ? ? ? ? # Both the mapping *and* the RGBA conversion failed: pretty

ValueError: 'c' argument has 1 elements, which is not acceptable for use with 'x' with size 211, 'y' with size 211.


出現(xiàn)這種問題的原因是plt.scatter(X[0, :], X[1, :], c=y, cmap=plt.cm.Spectral)這個函數(shù)太舊了贺纲,

解決方案如下即可

按提示找到reg_utils.py文件就在作業(yè)的同一個目錄。

在頂部import如下

import operator

from functools import reduce

然后分別在

plot_decision_boundary()和load_2D_dataset()找到plt.scatter方法褪测,替換成

plt.scatter(X[0, :], X[1, :], c=reduce(operator.add, y), s=40, cmap=plt.cm.Spectral)

第二坑:

TypeError Traceback (most recent call last)

d:\Anaconda3\lib\site-packages\matplotlib\colors.py in to_rgba(c, alpha)

? ? 173? ? try:

--> 174? ? ? ? rgba = _colors_full_map.cache[c, alpha]

? ? 175? ? except (KeyError, TypeError):? # Not in cache, or unhashable.

TypeError: unhashable type: 'numpy.ndarray'

During handling of the above exception, another exception occurred:

ValueError? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Traceback (most recent call last)

d:\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)

? 4231? ? ? ? ? ? try:? # Then is 'c' acceptable as PathCollection facecolors?

-> 4232? ? ? ? ? ? ? ? colors = mcolors.to_rgba_array(c)

? 4233? ? ? ? ? ? ? ? n_elem = colors.shape[0]

d:\Anaconda3\lib\site-packages\matplotlib\colors.py in to_rgba_array(c, alpha)

? ? 274? ? for i, cc in enumerate(c):

--> 275? ? ? ? result[i] = to_rgba(cc, alpha)

? ? 276? ? return result

d:\Anaconda3\lib\site-packages\matplotlib\colors.py in to_rgba(c, alpha)

? ? 175? ? except (KeyError, TypeError):? # Not in cache, or unhashable.

--> 176? ? ? ? rgba = _to_rgba_no_colorcycle(c, alpha)

? ? 177? ? ? ? try:

d:\Anaconda3\lib\site-packages\matplotlib\colors.py in _to_rgba_no_colorcycle(c, alpha)

? ? 230? ? if len(c) not in [3, 4]:

--> 231? ? ? ? raise ValueError("RGBA sequence should have length 3 or 4")

? ? 232? ? if len(c) == 3 and alpha is None:

ValueError: RGBA sequence should have length 3 or 4

During handling of the above exception, another exception occurred:

ValueError? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Traceback (most recent call last)

<ipython-input-7-a9a84d38b990> in <module>

----> 1 train_X, train_Y, test_X, test_Y = load_2D_dataset()

~\Desktop\COURSE 2 Improving Deep Neural Networks Hyperparameter tuning, Regularization and Optimization\week5\Regularization\reg_utils.py in load_2D_dataset()

? ? 332? ? train_X = data['X'].T

? ? 333? ? train_Y = data['y'].T

--> 334? ? test_X = data['Xval'].T

? ? 335? ? test_Y = data['yval'].T

? ? 336

d:\Anaconda3\lib\site-packages\matplotlib\pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, data, **kwargs)

? 2860? ? ? ? vmin=vmin, vmax=vmax, alpha=alpha, linewidths=linewidths,

? 2861? ? ? ? verts=verts, edgecolors=edgecolors, **({"data": data} if data

-> 2862? ? ? ? is not None else {}), **kwargs)

? 2863? ? sci(__ret)

? 2864? ? return __ret

d:\Anaconda3\lib\site-packages\matplotlib\__init__.py in inner(ax, data, *args, **kwargs)

? 1808? ? ? ? ? ? ? ? ? ? ? ? "the Matplotlib list!)" % (label_namer, func.__name__),

? 1809? ? ? ? ? ? ? ? ? ? ? ? RuntimeWarning, stacklevel=2)

-> 1810? ? ? ? ? ? return func(ax, *args, **kwargs)

? 1811

? 1812? ? ? ? inner.__doc__ = _add_data_doc(inner.__doc__,

d:\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)

? 4243? ? ? ? ? ? ? ? ? ? ? ? "acceptable for use with 'x' with size {xs}, "

? 4244? ? ? ? ? ? ? ? ? ? ? ? "'y' with size {ys}."

-> 4245? ? ? ? ? ? ? ? ? ? ? ? .format(nc=n_elem, xs=x.size, ys=y.size)

? 4246? ? ? ? ? ? ? ? ? ? )

? 4247? ? ? ? ? ? ? ? # Both the mapping *and* the RGBA conversion failed: pretty

ValueError: 'c' argument has 1 elements, which is not acceptable for use with 'x' with size 211, 'y' with size 211.

==========================================

Traceback (most recent call last):

? File "d:\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3296, in run_code

? ? exec(code_obj, self.user_global_ns, self.user_ns)

? File "<ipython-input-1-0b76c4151612>", line 4, in <module>

? ? from reg_utils import sigmoid, relu, plot_decision_boundary, initialize_parameters, load_2D_dataset, predict_dec

? File "C:\Users\34657\Desktop\COURSE 2 Improving Deep Neural Networks Hyperparameter tuning, Regularization and Optimization\week5\Regularization\reg_utils.py", line 328

? ? plt.scatter(X[0, :], X[1, :], c=reduce(operator.add, Y), s=40, cmap=plt.cm.Spectral)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ^

TabError: inconsistent use of tabs and spaces in indentation

分析

提示空格問題猴誊??然而所有打開來看又很正常拔甏搿懈叹!

其實(shí)很多表面的正常,背后都隱藏著不正常分扎,你看到的是隔開了项阴,但實(shí)際上它可能是/t而不是我們普遍認(rèn)為的/space

參考這位網(wǎng)友的方案https://blog.csdn.net/qq_41096996/article/details/85947560

將上面的真空格替換錯誤行的假空格就OK了

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子环揽,更是在濱河造成了極大的恐慌略荡,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,470評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件歉胶,死亡現(xiàn)場離奇詭異汛兜,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)通今,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,393評論 3 392
  • 文/潘曉璐 我一進(jìn)店門粥谬,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人辫塌,你說我怎么就攤上這事漏策。” “怎么了臼氨?”我有些...
    開封第一講書人閱讀 162,577評論 0 353
  • 文/不壞的土叔 我叫張陵掺喻,是天一觀的道長。 經(jīng)常有香客問我储矩,道長感耙,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,176評論 1 292
  • 正文 為了忘掉前任持隧,我火速辦了婚禮即硼,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘屡拨。我一直安慰自己只酥,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,189評論 6 388
  • 文/花漫 我一把揭開白布呀狼。 她就那樣靜靜地躺著裂允,像睡著了一般。 火紅的嫁衣襯著肌膚如雪赠潦。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,155評論 1 299
  • 那天草冈,我揣著相機(jī)與錄音她奥,去河邊找鬼。 笑死怎棱,一個胖子當(dāng)著我的面吹牛哩俭,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播拳恋,決...
    沈念sama閱讀 40,041評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼凡资,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起隙赁,我...
    開封第一講書人閱讀 38,903評論 0 274
  • 序言:老撾萬榮一對情侶失蹤垦藏,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后伞访,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體掂骏,經(jīng)...
    沈念sama閱讀 45,319評論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,539評論 2 332
  • 正文 我和宋清朗相戀三年厚掷,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了弟灼。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,703評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡冒黑,死狀恐怖田绑,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情抡爹,我是刑警寧澤掩驱,帶...
    沈念sama閱讀 35,417評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站豁延,受9級特大地震影響昙篙,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜诱咏,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,013評論 3 325
  • 文/蒙蒙 一苔可、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧袋狞,春花似錦焚辅、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,664評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至早处,卻和暖如春湾蔓,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背砌梆。 一陣腳步聲響...
    開封第一講書人閱讀 32,818評論 1 269
  • 我被黑心中介騙來泰國打工默责, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人咸包。 一個月前我還...
    沈念sama閱讀 47,711評論 2 368
  • 正文 我出身青樓桃序,卻偏偏與公主長得像,于是被迫代替她去往敵國和親烂瘫。 傳聞我的和親對象是個殘疾皇子媒熊,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,601評論 2 353