資源簡介
GAN 和 DCGAN 網絡生成圖像,采用python語言編寫程序實現生成網絡,并給出網絡的具體訓練代碼
代碼片段和文件信息
“““
Modification?of?https://github.com/stanfordnlp/treelstm/blob/master/scripts/download.py
Downloads?the?following:
-?Celeb-A?dataset
-?LSUN?dataset
-?MNIST?dataset
“““
from?__future__?import?print_function
import?os
import?sys
import?gzip
import?json
import?shutil
import?zipfile
import?argparse
import?requests
import?subprocess
from?tqdm?import?tqdm
from?six.moves?import?urllib
parser?=?argparse.ArgumentParser(description=‘Download?dataset?for?DCGAN.‘)
parser.add_argument(‘datasets‘?metavar=‘N‘?type=str?nargs=‘+‘?choices=[‘celebA‘?‘lsun‘?‘mnist‘]
???????????help=‘name?of?dataset?to?download?[celebA?lsun?mnist]‘)
def?download(url?dirpath):
??filename?=?url.split(‘/‘)[-1]
??filepath?=?os.path.join(dirpath?filename)
??u?=?urllib.request.urlopen(url)
??f?=?open(filepath?‘wb‘)
??filesize?=?int(u.headers[“Content-Length“])
??print(“Downloading:?%s?Bytes:?%s“?%?(filename?filesize))
??downloaded?=?0
??block_sz?=?8192
??status_width?=?70
??while?True:
????buf?=?u.read(block_sz)
????if?not?buf:
??????print(‘‘)
??????break
????else:
??????print(‘‘?end=‘\r‘)
????downloaded?+=?len(buf)
????f.write(buf)
????status?=?((“[%-“?+?str(status_width?+?1)?+?“s]?%3.2f%%“)?%
??????(‘=‘?*?int(float(downloaded)?/?filesize?*?status_width)?+?‘>‘?downloaded?*?100.?/?filesize))
????print(status?end=‘‘)
????sys.stdout.flush()
??f.close()
??return?filepath
def?download_file_from_google_drive(id?destination):
??URL?=?“https://docs.google.com/uc?export=download“
??session?=?requests.Session()
??response?=?session.get(URL?params={?‘id‘:?id?}?stream=True)
??token?=?get_confirm_token(response)
??if?token:
????params?=?{?‘id‘?:?id?‘confirm‘?:?token?}
????response?=?session.get(URL?params=params?stream=True)
??save_response_content(response?destination)
def?get_confirm_token(response):
??for?key?value?in?response.cookies.items():
????if?key.startswith(‘download_warning‘):
??????return?value
??return?None
def?save_response_content(response?destination?chunk_size=32*1024):
??total_size?=?int(response.headers.get(‘content-length‘?0))
??with?open(destination?“wb“)?as?f:
????for?chunk?in?tqdm(response.iter_content(chunk_size)?total=total_size
??????????????unit=‘B‘?unit_scale=True?desc=destination):
??????if?chunk:?#?filter?out?keep-alive?new?chunks
????????f.write(chunk)
def?unzip(filepath):
??print(“Extracting:?“?+?filepath)
??dirpath?=?os.path.dirname(filepath)
??with?zipfile.ZipFile(filepath)?as?zf:
????zf.extractall(dirpath)
??os.remove(filepath)
def?download_celeb_a(dirpath):
??data_dir?=?‘celebA‘
??if?os.path.exists(os.path.join(dirpath?data_dir)):
????print(‘Found?Celeb-A?-?skip‘)
????return
??filename?drive_id??=?“img_align_celeba.zip“?“0B7EVK8r0v71pZjFTYXZWM3FlRnM“
??save_path?=?os.path.join(dirpath?filename)
??if?os.path.exists(save_path):
????print(‘[*]?{}?already?exists‘.format(save_path))
??else:
????download_file_from_google_drive(drive_id?save_path)
??zip_dir?=?‘‘
??with?zipfile.ZipFile(save_path)?as?zf:
????zip_dir?=?z
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-07-22?02:35??chapter_8\
?????文件????????8647??2018-07-22?02:35??chapter_8\utils.py
?????文件????????3656??2018-07-22?02:35??chapter_8\ops.py
?????文件???????20079??2018-07-22?02:35??chapter_8\model.py
?????文件????????3945??2018-07-22?02:35??chapter_8\main.py
?????文件????????5375??2018-07-22?02:35??chapter_8\download.py
?????文件????????3338??2018-07-22?02:35??chapter_8\README_eng.md
?????文件????????1766??2018-07-22?02:35??chapter_8\README.md
?????文件????????1078??2018-07-22?02:35??chapter_8\LICENSE
?????文件??????150616??2018-07-22?02:35??chapter_8\DCGAN.png
?????文件?????????989??2018-07-22?02:35??chapter_8\.gitignore
?????目錄???????????0??2018-07-22?02:35??chapter_8\web\
?????文件???????28424??2018-07-22?02:35??chapter_8\web\index.html
?????文件?????????283??2018-07-22?02:35??chapter_8\web\app.py
?????目錄???????????0??2018-07-22?02:35??chapter_8\assets\
?????文件????15299008??2018-07-22?02:35??chapter_8\assets\training.gif
?????文件??????529986??2018-07-22?02:35??chapter_8\assets\result_16_01_04_.png
?????文件??????522641??2018-07-22?02:35??chapter_8\assets\result_16_01_04.png
?????文件??????591739??2018-07-22?02:35??chapter_8\assets\result_16_01_03.png
?????文件???????27204??2018-07-22?02:35??chapter_8\assets\mnist3.png
?????文件???????26911??2018-07-22?02:35??chapter_8\assets\mnist2.png
?????文件???????28739??2018-07-22?02:35??chapter_8\assets\mnist1.png
?????文件??????107790??2018-07-22?02:35??chapter_8\assets\g_loss.png
?????文件???????98740??2018-07-22?02:35??chapter_8\assets\d_loss.png
?????文件??????389671??2018-07-22?02:35??chapter_8\assets\d_hist.png
?????文件??????354853??2018-07-22?02:35??chapter_8\assets\d__hist.png
?????文件??????499759??2018-07-22?02:35??chapter_8\assets\custom_dataset.png
?????目錄???????????0??2018-07-22?02:35??chapter_8\web\videos\
?????文件?????3870558??2018-07-22?02:35??chapter_8\web\videos\training.mp4
?????文件?????1079329??2018-07-22?02:35??chapter_8\web\videos\random.mp4
?????文件?????1922773??2018-07-22?02:35??chapter_8\web\videos\background.mp4
............此處省略60個文件信息
- 上一篇:吳恩達深度學習作業代碼官方答案.pdf
- 下一篇:Python金融大數據分析.zip
評論
共有 條評論