tqdmで精神衛生を保つ
アドベントカレンダー5日目です。
adventar.org
今日はプログレスバーを表示するtqdmについて書いていきます。
tqdmとは
tqdm means “progress” in Arabic (taqadum, تقدّم) and is an abbreviation for “I love you so much” in Spanish (te quiero demasiado)
https://pypi.org/project/tqdm/
tqdmはアラビア語でプログレスを意味し、
スペイン語での "I love you so much"の略語らしいです(豆知識)。
機能としてはプログレスバーを表示し、処理速度も簡易ですが表示されます。
使用例
for文の中に組み込むことで、プログレスバーを表示できます。
from tqdm import tqdm import time for i in tqdm(range(10)): time.sleep(1)
jupyter notebookを使っている際にはimportを変えることで、よりリッチな表示にできます。
from tqdm import tqdm_notebook as tqdm import time for i in tqdm(range(10)): time.sleep(1)
アニメーションにしました。
ちょっと楽しいですね。
プログレスバーについて説明を出すこともできます。
from tqdm import tqdm_notebook as tqdm import time for i in tqdm(range(3), desc="first loop"): for j in tqdm(range(10), desc="second loop"): time.sleep(0.1)
pythonでバイナリを扱う
一人アドベントカレンダー4日目です。
たまたまpythonでバイナリを扱ったのでそれに関してのメモを書いていきます。
基本的な扱い
基本的にはstructで扱えばいいと思います。
パックするときはpackを使い、フォーマット文字列を指定します。
アンパックするときにはunpackを使い、同じフォーマット文字列を指定すれば戻すことができます。
import struct x = struct.pack('II', 1000, 0) print(x) >> b'\xe8\x03\x00\x00\x00\x00\x00\x00' print(struct.unpack('II', x)) >> (1000, 0)
今回はバイナリデータを読み込むためにこれを使いました。
f = open(hoge.txt, "rb") offset, length = struct.unpack("II",f.read(8))
こんな感じでほしいデータを引っ張ることができました。
参考情報
やはりドキュメントが一番で、あまり日本語では関連記事はありません。
7.1. struct — バイト列をパックされたバイナリデータとして解釈する — Python 3.6.5 ドキュメント
PythonでバイナリをあつかうためのTips - Qiita
2018年度Amazonで買ってよかったもの
アドベントカレンダー3日目です。
今日は技術的な話ではなく、Amazonで買ってよかったものを紹介したいと思います。
今年は比較的Amazonで購入した金額が多く、157417円ほど使っていたようです。
調査方法は以下のブログを参考にしました。
Amazon歴13年で使用した金額を出力してみました - 力こそパワー
では、紹介していきます。
- LOGICOOL ウェブカム HD画質 120万画素 C270
- 難消化性デキストリン(水溶性食物繊維)400g(微顆粒品)
- F-Foto キャノン EOS Kiss X9i/X9/X8i/X7i/80D/70D/9000D/8000D ダブルズームキット に適合 EW-63C & ET-63 互換フード 、レンズ 保護 フィルター 2枚 と 一眼カメラケース のセット
- LP-E17 Newmowa 互換バッテリー 2個 + 充電器 対応機種 Canon LP-E17 Canon EOS M3 M5 M6 200D 750D 760D 800D Rebel T6i T6s 8000D 9000D Kiss X8i Kiss X9
- APAGARD(アパガード) スモーキン
- 竹井器物製作所 フィーノ コーヒードリップポット 1.2L
- IZUMI VIDAN 往復式シェーバー ソリッドシリーズ 3枚刃 レッド IZF-V26-R
- なとり 激辛柿の種&ピーナッツ 60g×10袋
- ドライペット 除湿剤 ふとん快適シート くりかえし再生タイプ 1シート入
- 【正規品】 BODUM ボダム BRAZIL フレンチプレスコーヒーメーカー 1.0L ブラック
- まとめ
LOGICOOL ウェブカム HD画質 120万画素 C270
売り上げランキング: 118
あとは部屋が暗くても比較的きれいに映るところもいいですね。
難消化性デキストリン(水溶性食物繊維)400g(微顆粒品)
売り上げランキング: 90
F-Foto キャノン EOS Kiss X9i/X9/X8i/X7i/80D/70D/9000D/8000D ダブルズームキット に適合 EW-63C & ET-63 互換フード 、レンズ 保護 フィルター 2枚 と 一眼カメラケース のセット
売り上げランキング: 25,958
売り上げランキング: 1,514
APAGARD(アパガード) スモーキン
売り上げランキング: 417
竹井器物製作所 フィーノ コーヒードリップポット 1.2L
売り上げランキング: 4,687
IZUMI VIDAN 往復式シェーバー ソリッドシリーズ 3枚刃 レッド IZF-V26-R
売り上げランキング: 761
なとり 激辛柿の種&ピーナッツ 60g×10袋
ドライペット 除湿剤 ふとん快適シート くりかえし再生タイプ 1シート入
売り上げランキング: 1,592
【正規品】 BODUM ボダム BRAZIL フレンチプレスコーヒーメーカー 1.0L ブラック
まとめ
今日はAmazonで買ってよかったものを紹介しました。
最近では、明らかに翻訳っぽい商品レビューも多いので、気を付けるようにしましょう。
深層学習を学ぶ人におすすめのツイッターアカウント
アドベントカレンダー2日目です。
深層学習について学んだり、新しい情報をキャッチアップすることは結構大変です。
毎日新しい論文を確認したり、海外の英語の情報を見てる人もいますが、
誰しもが行えるわけではありません。
そこで今回は、できるだけ気楽に情報を集められるツイッターのアカウントを紹介していきます。
- piqcy (@icoxfog417) | Twitter
- Ryobot | りょぼっと (@_Ryobot) | Twitter
- aidiary (@sylvan5) | Twitter
- arXivTimes (@arxivtimes) | Twitter
- 人工知能,機械学習関係ニュース研究所 (@AI_m_lab) | Twitter
- DLHacks (@DL_Hacks) | Twitter
- まとめ
piqcy (@icoxfog417) | Twitter
英語の論文や海外のツイートなどを翻訳してツイートしてくれます。
情報も画像や自然言語処理などいろんな分野についてツイートされています。
GANによる生成過程において、どのユニットがどのクラス(ドアや木)の生成に寄与しているかを解析する手法を提案。ユニットの生成結果(特徴マップ)のヒートマップと画像のセグメンテーションのオーバーラップ(IoU)を比較し特定を行う。これを応用した生成(対象クラスを出し入れする)も行なっている https://t.co/qSJFHHvMZi
— piqcy (@icoxfog417) 2018年11月29日
Ryobot | りょぼっと (@_Ryobot) | Twitter
メンヘラちゃんが最新論文について紹介してくれるツイートが有名です。
内容的に難しい論文も雰囲気をわかりやすくつかむことができると思います。
逆翻訳がヤバいスコアを叩き出しててびっくりした.おそらくAttention以降では最大の性能uphttps://t.co/ssaQw2s22f
— Ryobot | りょぼっと (@_Ryobot) 2018年11月15日
深層学習はえげつない手法が突然ポッとでてくるからおもろい pic.twitter.com/RwyrjCn8Rx
aidiary (@sylvan5) | Twitter
深層学習に関する記事や有益な情報をリツイートしています。
手描きのような似顔絵を生成するAI、マイクロソフトらが開発 https://t.co/Cn3wmz8ahQ
— aidiary (@sylvan5) 2018年11月28日
arXivTimes (@arxivtimes) | Twitter
論文の要約情報をまとめてるサイト、arXivTimesの更新情報をツイートするアカウントです。
Unsupervised Word Discovery with Segmental Neural Language Models https://t.co/cUPzw42SyN
— arXivTimes (@arxivtimes) 2018年11月27日
人工知能,機械学習関係ニュース研究所 (@AI_m_lab) | Twitter
AIや深層学習についての記事をツイートするアカウントです。
記述的な話というよりは、一般的なAIに関するニュースが多いです。
気になる記事ですね。
— 人工知能,機械学習関係ニュース研究所 (@AI_m_lab) 2018年11月29日
▼AIが描いた肖像画は、こうして43万ドルの高値がついた|https://t.co/U4eEFNE68Nhttps://t.co/PZACK4QUsr#AI
DLHacks (@DL_Hacks) | Twitter
東京大学の松尾研が運営してるアカウントで、論文の輪読会スライドがあげられています。
電子商取引の注文に対してGANを提案。注文を密で低次元な方法で表現し、WGANを適用する(ecGAN)。また、特定の商品を購入する注文を生成するec2GANも提案。生成された注文が尤もらしいことを、それぞれ定性的、定量的に確認した。https://t.co/pefgdfsgB2
— DLHacks (@DL_Hacks) 2018年11月12日
まとめ
今回はおすすめのツイッターアカウントを紹介しました。
ほかにもおすすめのアカウントがあったらぜひ教えてください。
chainerのexamplesについて
一人アドベントカレンダー1日目です。
adventar.org
昨年に引き続きやっていきますが、
去年よりは忙しいのですべて埋まるかは怪しいです。
今日はChainerのexamplesについて書いていきたいと思います。
github.com
Chainerのexamplesは少しずつ数が増えていて、
昔はmnist, imagenet, ptb, cifar, vae ....と、
そんな感じだったと思うのですが、
現在ではこれだけあります。
実際にそれぞれ見たことある方はわかると思いますが、詳しい説明や実行方法については触れられていないものもあります。
そこで、今回はそれぞれがどういうものなのか、ということを順に説明したいと思います。
- caffe_export
- chainermn
- cifar
- dcgan
- glance
- image_captioning
- imagenet
- memnn
- mnist
- modelzoo
- pix2pix
- pos
- ptb
- reinforcement_learning
- sentiment
- seq2seq
- serialization
- static_graph_optimizations
- text_classification
- vae
- wavenet
- word2vec
- まとめ
caffe_export
This example shows how to export Chainer models into Caffe protobuf format. With this example, you can easily export the following five pre-trained models:
https://github.com/chainer/chainer/tree/master/examples/caffe_export
・GoogLeNet
・ResNet50
・ResNet101
・ResNet152
・VGG16
読んでそのままですが、ChainerのモデルをCaffeのprotobuf形式にexportするもののようです。
この例では、上記の5つの学習済みモデルをexportする例が示されています。
chainermn
特に説明は書かれていませんが、ChainerMNに関するサンプルだと思います。
ChainerMNに関する詳しい話はこちらである程度わかると思います。
Overview — ChainerMN 1.3.1 documentation
複数のGPUを使っている人、複数のノードを用いて学習する人向けの例で、並列処理をしたい人は参考になるかもしれません。ChainerMN自体があまり個人向けではないかも知れませんが。
cifar
https://github.com/chainer/chainer/tree/master/examples/cifarConvolutional neural networks for CIFAR-10 and CIFAR-100 Classification
This is an example of a convolutional neural network (convnet) applied to an image classification task using the CIFAR-10 or CIFAR-100 dataset. The CIFAR datasets can be a good choice for initial experiments with convnets because the size and number of images is small enough to allow typical models to be trained in a reasonable amount of time. However, the classification task is still challenging because natural images are used.
CIFAR-10、CIFAR-100と呼ばれるデータセットがあります。
CIFAR-10は10クラスにラベル付けされた画像のデータセットで、
CIFAR-100は100クラスにラベル付けされたデータセットです。
主に画像分類に用いられるデータセットで、このサンプルでは、CNNを用いて学習を行うようです。
dcgan
https://github.com/chainer/chainer/tree/master/examples/dcganDCGAN
This is an example implementation of DCGAN (https://arxiv.org/abs/1511.06434) using trainer.
This code uses Cifar-10 dataset by default. You can use your own dataset by specifying --dataset argument to the directory consisting of image files for training. The model assumes the resolution of an input image is 32x32. If you want to use another image resolution, you need to change the network architecture in net.py.
DCGANと呼ばれる、画像生成によく使われるネットワークのサンプルですね。この例では、cifar-10データセットを用いて学習を行えるようです。
glance
https://github.com/chainer/chainer/tree/master/examples/glanceMulti-Layer Perceptron for mushroom lethality categorization
This is a minimal example to write a feed-forward net. The code consists of three parts: dataset preparation, network and optimizer definition and learning loop. This is a common routine to write a learning process of networks with dataset that is small enough to fit into memory.
MLPを使って、マッシュルームのデータセットを分類するサンプルです。この例は、フィードフォワードネットワークの参考になると思います。
image_captioning
https://github.com/chainer/chainer/tree/master/examples/image_captioningImage Captioning with Convolutional Neural Networks
This is an example implementation of Show and Tell: A Neural Image Caption Generator (https://arxiv.org/abs/1411.4555) a generative image captioning model using a neural network with convolutional and recurrent layers. Given an image, this model generates a sentence that describes it.
イメージキャプションに関するサンプルです。モデルとしては、CNN+RNNを使うようです。
imagenet
https://github.com/chainer/chainer/tree/master/examples/imagenetDescription
This is an experimental example of learning from the ILSVRC2012 classification dataset. It requires the training and validation dataset of following format:
・Each line contains one training example.
・Each line consists of two elements separated by space(s).
・The first element is a path to 256x256 RGB image.
・The second element is its ground truth label from 0 to 999.
ILSVRC2012の分類データセットのサンプルです。デフォルトalexnetやgooglenet、resnetなどのモデルを使うことができます。
memnn
https://github.com/chainer/chainer/tree/master/examples/memnnEnd-to-end memory networks example
This is an example of end-to-end memory networks[1].
[1] Sainbayar Sukhbaatar, Arthur szlam, Jason Weston and Rob Fergus. End-To-End Memory Networks. https://papers.nips.cc/paper/5846-end-to-end-memory-networks
メモリーネットワークに関するサンプルです。
独特なモデルをしてると思うので、見てみると面白いかもしれません。
mnist
https://github.com/chainer/chainer/tree/master/examples/mnistMulti-Layer Perceptron for MNIST Classification
This is a minimal example to write a feed-forward net. The code consists of three parts: dataset preparation, network and optimizer definition and learning loop. This is a common routine to write a learning process of networks with dataset that is small enough to fit into memory.
シンプルなMLPを使ったMNISTの分類のサンプルです。
MNISTは0~9までの数字の画像のデータセットで、一番基礎となるサンプルだと思います。
modelzoo
https://github.com/chainer/chainer/tree/master/examples/modelzooEvaluate a Caffe reference model
This is an example of evaluating a Caffe reference model using ILSVRC2012 classification dataset. It requires the validation dataset in the same format as that for the imagenet example.
Model files can be downloaded by download_model.py. AlexNet and reference CaffeNet requires a mean file, which can be downloaded by download_mean_file.py.
先ほど出てきたILSVRC2012のデータセットを使って、caffeのモデルを評価するサンプルだと思います。
pix2pix
https://github.com/chainer/chainer/tree/master/examples/pix2pixchainer-pix2pix
chainer implementation of pix2pix https://phillipi.github.io/pix2pix/
pix2pixを実装したサンプルになります。生成系によく使われるモデルで、上記のURLから実際にデモを動かすことができるので、それを触ってみることでpix2pix自体のイメージはつかめるかもしれません。
pos
https://github.com/chainer/chainer/tree/master/examples/posPOS-tagging
This is an example of a POS-tagging problem for natural language processing. Part of speech (POS) is a category of word, such as noun and verb. POS-tagging problem is the task of assigning part of speech to each word in a sentence. This problem can be formulated as a sequential labeling problem. So, you can apply this example to another problems such as named entity recognition.
This example uses traditional linear-chain CRF model. And of course you can extends this model with RNN, LSTM, Bi-LSTM and CNN.
自然言語処理のPOSタグ付けに関するサンプルです。
モデル自体はlinear-chain CRFを使っているようです。
ptb
https://github.com/chainer/chainer/tree/master/examples/ptbRecurrent Net Language Model
This is an example of a recurrent net for language modeling. The network is trained to predict the word given the preceding word sequence.
This example is based on the following RNNLM implementation written in Torch7. https://github.com/tomsercu/lstm
次の単語を予想していくRNNのサンプルです。
ちなみにptbはPenn Tree Bankの略で、使用するデータセットの名前です。
reinforcement_learning
https://github.com/chainer/chainer/tree/master/examples/reinforcement_learningReinforcement Learning Examples
These are minimal examples of writing reinforcement learning agents. You need to install gym before running the examples.
・dqn_cartpole.py implements DQN and DoubleDQN and supports discrete-action tasks.
・ddpg_pendulum.py implements DDPG and supports continuous-action tasks.
強化学習に関するサンプルで、cartpole(棒を倒さないように保ゲーム)とpendulum(振り子のゲーム)を動かすサンプルです。
ネットワークにはDQNとDoubleDQNなどが使われているようです。
chainerrlは使われていないみたいです。
sentiment
https://github.com/chainer/chainer/tree/master/examples/sentimentRecursive Nets for Sentiment Analysis
This example implements the simple recursive model by Richard Socher. It requires the preprocessed dataset which is available by running download.py.
感情分析に関するサンプルです。
RecursiveNetと呼ばれるネットワークが使われています。
seq2seq
https://github.com/chainer/chainer/tree/master/examples/seq2seqSequence-to-sequnce learning example for machine translation
This is a minimal example of sequence-to-sequence learning. Sequence-to-sequence is a learning model that converts an input sequence into an output sequence. You can regard many tasks in the natural language processing field as this type of task, such as machine translation, dialogue and summarization.
自然言語処理によく使われるseq2seqのサンプルです。
ネットワークには、NStepLSTMが使用されているので、そちらの参考にもなるかもしれません。
serialization
https://github.com/chainer/chainer/tree/master/examples/serializationSerialization
This example intends to show how to use serializers with minimal code. These scripts show two ways to save/load snapshots using NumPy and H5Py, so please ensure that you have installed h5py package besides NumPy preliminary.
モデルの保存や読み込みなどのサンプルです。
この例では、H5Pyを使う方法とserializersを使う方法が示されています。
static_graph_optimizations
https://github.com/chainer/chainer/tree/master/examples/static_graph_optimizationsDemonstration of "static subgraph optimizations" feature
The subfolders in this directory contain versions of the following Chainer examples that were modified to support this feature. Since the static graph optimizations feature is experimental, these examples might be unstable.
静的グラフ最適化に関するサンプルとのことで、まだ実験的な機能のようです。
text_classification
https://github.com/chainer/chainer/tree/master/examples/text_classificationNeural Networks for Text Classification
This is an example of text classification using typical neural networks. This code can switch choices below:
・LSTM
・CNN + MLP
・BoW + MLP
・Character-based variant models of those
文書分類に関するサンプルです。
LSTM、CNN+MLP、BoW+MLPなどのネットワークを使って学習をすることができます。
vae
https://github.com/chainer/chainer/tree/master/examples/vaeVariational AutoEncoder
This is a sample implementation of variational autoencoder.
This method is proposed by Kingma and Welling, Auto-Encoding Variational Bayes, 2014.
Variational AutoEncoder(VAE)に関するサンプルです。
mnistのデータセットを使い、画像を生成するようです。
wavenet
https://github.com/chainer/chainer/tree/master/examples/wavenetWaveNet
A Chainer implementation of mel-spectrogram vocoder using WaveNet.
一時期話題になったWaveNetのChainer実装です。
音声処理に興味がある人はいいかも知れません。
word2vec
https://github.com/chainer/chainer/tree/master/examples/word2vecWord Embedding
This is an example of word embedding. We implemented Mikolov's Skip-gram model and Continuous-BoW model with Hierarchical softmax and Negative sampling.
word embeddingに関するサンプルです。
word2vec自体は知ってる人も多いと思います。
まとめ
今回はChainerのexamplesを軽く紹介しました。
以前よりもかなり種類が増えていて説明も少し細かくなっています。
みなさんも画像や自然言語、いろんなサンプルを試してみてくださいね。
複数のファイルをunzipする
複数のファイルをunzipする場合、こういう書き方が思い浮かぶと思います。
unzip *.zip
実際にこのコマンドを打ち込んでも解凍はできません。
以下のようなエラーが出ました。
End-of-central-directory signature not found. Either this file is not a zipfile, or it constitutes one disk of a multi-part archive. In the latter case the central directory and zipfile comment will be found on the last disk(s) of this archive.
書き方を少しだけ変えるだけで複数ファイルの解凍ができます。ダブルクオーテーションで囲うだけです。
unzip "*.zip"
XGBoostでInvalid Parameter format for max_depth expect int but valueが出る
XGBoostでパラメータを設定する際にエラーが出ました。
model = xgb.XGBRegressor(params)
XGBoostError: b"Invalid Parameter format for max_depth expect int but value='{'eval_metric': 'rmse', 'learning_rate': 0.1}'"
こちらを参考にしたところ、動くようになりました。
github.com
model = xgb.XGBRegressor(**params)