语义分割和数据集 讨论区

http://zh.diveintodeeplearning.org/chapter_computer-vision/semantic-segmentation-and-dataset.html

image
请问为什么imgs一定要把train_images[0:n] 和 train_labels[0:n] 加起来才能显示呢?单独显示train_images[0:n]会报错?

请问如何将自己的数据集准备成ade20k的格式?有这方面的教程么?
目的是可以直接使用gluoncv里的PSPNet进行语义分割。

不使用ade20k的数据格式也可以用gluoncv提供的PSPNet训练。你仔细查一下源码,我记得basemodel是resnet50的话要求格式为480*480,你只需要把自己的数据集的数据预处理成模型要求的大小就好

1赞

参看前面的例子可以知道,d2l.show_images的实现,对Axes对象是采用双下标索引的,源代码如:
axes[i][j].imshow(imgs[i * num_cols + j].asnumpy()).也就是说,要求前面subplot函数返回的axes必须是二维的.你如果在d2l.show_images的输入参数里令行数=1或者列数=1,它生成的axes只是一维的,无法进行二维索引,你可以print
axes看一下.
如果只想打印train_images或者train_labels,那么只要在,d2l.show_images输入参数里.行数和列数都不等于1即可.
比如打印前9张训练图片,
imgs = train_features[0:9]
d2l.show_images(imgs,3,3);
是不会报错的

通过这个URL无法连接到数据库 无法下载voc数据
报错信息:
Downloading …/data\VOCtrainval_11-May-2012.tar from http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar
download failed due to ProxyError(MaxRetryError(“HTTPConnectionPool(host=‘127.0.0.1’, port=7890): Max retries exceeded with url: http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar (Caused by ProxyError(‘Cannot connect to proxy.’, RemoteDisconnected(‘Remote end closed connection without response’,)))”,),), retrying, 4 attempts left
Downloading …/data\VOCtrainval_11-May-2012.tar from http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar
download failed due to ProxyError(MaxRetryError(“HTTPConnectionPool(host=‘127.0.0.1’, port=7890): Max retries exceeded with url: http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar (Caused by ProxyError(‘Cannot connect to proxy.’, RemoteDisconnected(‘Remote end closed connection without response’,)))”,),), retrying, 3 attempts left
Downloading …/data\VOCtrainval_11-May-2012.tar from http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar
download failed due to ProxyError(MaxRetryError(“HTTPConnectionPool(host=‘127.0.0.1’, port=7890): Max retries exceeded with url: http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar (Caused by ProxyError(‘Cannot connect to proxy.’, RemoteDisconnected(‘Remote end closed connection without response’,)))”,),), retrying, 2 attempts left
Downloading …/data\VOCtrainval_11-May-2012.tar from http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar
download failed due to ProxyError(MaxRetryError(“HTTPConnectionPool(host=‘127.0.0.1’, port=7890): Max retries exceeded with url: http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar (Caused by ProxyError(‘Cannot connect to proxy.’, RemoteDisconnected(‘Remote end closed connection without response’,)))”,),), retrying, 1 attempt left
Downloading …/data\VOCtrainval_11-May-2012.tar from http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar

RemoteDisconnected Traceback (most recent call last)
d:\programdata\anaconda2\envs\gluon-gpu\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
600 body=body, headers=headers,
–> 601 chunked=chunked)
602

d:\programdata\anaconda2\envs\gluon-gpu\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
386 # otherwise it looks like a programming error was the cause.
–> 387 six.raise_from(e, None)
388 except (SocketTimeout, BaseSSLError, SocketError) as e:

d:\programdata\anaconda2\envs\gluon-gpu\lib\site-packages\urllib3\packages\six.py in raise_from(value, from_value)

d:\programdata\anaconda2\envs\gluon-gpu\lib\site-packages\urllib3\connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
382 try:
–> 383 httplib_response = conn.getresponse()
384 except Exception as e:

d:\programdata\anaconda2\envs\gluon-gpu\lib\http\client.py in getresponse(self)
1353 try:
-> 1354 response.begin()
1355 except ConnectionError:

d:\programdata\anaconda2\envs\gluon-gpu\lib\http\client.py in begin(self)
306 while True:
–> 307 version, status, reason = self._read_status()
308 if status != CONTINUE:

d:\programdata\anaconda2\envs\gluon-gpu\lib\http\client.py in _read_status(self)
275 # sending a valid response.
–> 276 raise RemoteDisconnected(“Remote end closed connection without”
277 " response")

RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

MaxRetryError Traceback (most recent call last)
d:\programdata\anaconda2\envs\gluon-gpu\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
439 retries=self.max_retries,
–> 440 timeout=timeout
441 )

d:\programdata\anaconda2\envs\gluon-gpu\lib\site-packages\urllib3\connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
638 retries = retries.increment(method, url, error=e, _pool=self,
–> 639 _stacktrace=sys.exc_info()[2])
640 retries.sleep()

d:\programdata\anaconda2\envs\gluon-gpu\lib\site-packages\urllib3\util\retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
387 if new_retry.is_exhausted():
–> 388 raise MaxRetryError(_pool, url, error or ResponseError(cause))
389

MaxRetryError: HTTPConnectionPool(host=‘127.0.0.1’, port=7890): Max retries exceeded with url: http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar (Caused by ProxyError(‘Cannot connect to proxy.’, RemoteDisconnected(‘Remote end closed connection without response’,)))

During handling of the above exception, another exception occurred:

ProxyError Traceback (most recent call last)
in
10 return voc_dir
11
—> 12 voc_dir = download_voc_pascal()

in download_voc_pascal(data_dir)
5 ‘/VOCtrainval_11-May-2012.tar’)
6 sha1 = ‘4e443f8a2eca6b1dac8a6c57641b67dd40621a49’
----> 7 fname = gutils.download(url, data_dir, sha1_hash=sha1)
8 with tarfile.open(fname, ‘r’) as f:
9 f.extractall(data_dir)

d:\programdata\anaconda2\envs\gluon-gpu\lib\site-packages\mxnet\gluon\utils.py in download(url, path, overwrite, sha1_hash, retries, verify_ssl)
343 retries -= 1
344 if retries <= 0: # pylint: disable=no-else-raise
–> 345 raise e
346 else:
347 print(‘download failed due to {}, retrying, {} attempt{} left’

d:\programdata\anaconda2\envs\gluon-gpu\lib\site-packages\mxnet\gluon\utils.py in download(url, path, overwrite, sha1_hash, retries, verify_ssl)
310 try:
311 print(‘Downloading {} from {}…’.format(fname, url))
–> 312 r = requests.get(url, stream=True, verify=verify_ssl)
313 if r.status_code != 200:
314 raise RuntimeError(‘Failed downloading url {}’.format(url))

d:\programdata\anaconda2\envs\gluon-gpu\lib\site-packages\requests\api.py in get(url, params, **kwargs)
70
71 kwargs.setdefault(‘allow_redirects’, True)
—> 72 return request(‘get’, url, params=params, **kwargs)
73
74

d:\programdata\anaconda2\envs\gluon-gpu\lib\site-packages\requests\api.py in request(method, url, **kwargs)
56 # cases, and look like a memory leak in others.
57 with sessions.Session() as session:
—> 58 return session.request(method=method, url=url, **kwargs)
59
60

d:\programdata\anaconda2\envs\gluon-gpu\lib\site-packages\requests\sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
506 }
507 send_kwargs.update(settings)
–> 508 resp = self.send(prep, **send_kwargs)
509
510 return resp

d:\programdata\anaconda2\envs\gluon-gpu\lib\site-packages\requests\sessions.py in send(self, request, **kwargs)
616
617 # Send the request
–> 618 r = adapter.send(request, **kwargs)
619
620 # Total elapsed time of the request (approximately)

d:\programdata\anaconda2\envs\gluon-gpu\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
500
501 if isinstance(e.reason, _ProxyError):
–> 502 raise ProxyError(e, request=request)
503
504 if isinstance(e.reason, _SSLError):

ProxyError: HTTPConnectionPool(host=‘127.0.0.1’, port=7890): Max retries exceeded with url: http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar (Caused by ProxyError(‘Cannot connect to proxy.’, RemoteDisconnected(‘Remote end closed connection without response’,)))

请问这段代码是什么意思呢?看不懂啊?
colormap2label = nd.zeros(256 ** 3)
for i, colormap in enumerate(VOC_COLORMAP):
colormap2label[(colormap[0] * 256 + colormap[1]) * 256 + colormap[2]] = i

本函数已保存在d2lzh包中方便以后使用

def voc_label_indices(colormap, colormap2label):
colormap = colormap.astype(‘int32’)
idx = ((colormap[:, :, 0] * 256 + colormap[:, :, 1]) * 256+ colormap[:, :, 2])
return colormap2label[idx]