アオイのプライバシーポリシー(Aoi's Privacy Policy)

Privacy Policy

Sakurabbit built the Aoi app as a Free app. This SERVICE is provided by Sakurabbit at no cost and is intended for use as is.

This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service.

If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy.

The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which is accessible at Aoi unless otherwise defined in this Privacy Policy.

Information Collection and Use

For a better experience, while using our Service, I may require you to provide us with certain personally identifiable information, including but not limited to Ad delivery. The information that I request will be retained on your device and is not collected by me in any way.

The app does use third party services that may collect information used to identify you.

Link to privacy policy of third party service providers used by the app

Log Data

I want to inform you that whenever you use my Service, in a case of an error in the app I collect data and information (through third party products) on your phone called Log Data. This Log Data may include information such as your device Internet Protocol (“IP”) address, device name, operating system version, the configuration of the app when utilizing my Service, the time and date of your use of the Service, and other statistics.

Cookies

Cookies are files with a small amount of data that are commonly used as anonymous unique identifiers. These are sent to your browser from the websites that you visit and are stored on your device's internal memory.

This Service does not use these “cookies” explicitly. However, the app may use third party code and libraries that use “cookies” to collect information and improve their services. You have the option to either accept or refuse these cookies and know when a cookie is being sent to your device. If you choose to refuse our cookies, you may not be able to use some portions of this Service.

Service Providers

I may employ third-party companies and individuals due to the following reasons:

  • To facilitate our Service;
  • To provide the Service on our behalf;
  • To perform Service-related services; or
  • To assist us in analyzing how our Service is used.

I want to inform users of this Service that these third parties have access to your Personal Information. The reason is to perform the tasks assigned to them on our behalf. However, they are obligated not to disclose or use the information for any other purpose.

Security

I value your trust in providing us your Personal Information, thus we are striving to use commercially acceptable means of protecting it. But remember that no method of transmission over the internet, or method of electronic storage is 100% secure and reliable, and I cannot guarantee its absolute security.

Links to Other Sites

This Service may contain links to other sites. If you click on a third-party link, you will be directed to that site. Note that these external sites are not operated by me. Therefore, I strongly advise you to review the Privacy Policy of these websites. I have no control over and assume no responsibility for the content, privacy policies, or practices of any third-party sites or services.

Children’s Privacy

These Services do not address anyone under the age of 13. I do not knowingly collect personally identifiable information from children under 13 years of age. In the case I discover that a child under 13 has provided me with personal information, I immediately delete this from our servers. If you are a parent or guardian and you are aware that your child has provided us with personal information, please contact me so that I will be able to do necessary actions.

Changes to This Privacy Policy

I may update our Privacy Policy from time to time. Thus, you are advised to review this page periodically for any changes. I will notify you of any changes by posting the new Privacy Policy on this page.

This policy is effective as of 2021-06-18

Contact Us

If you have any questions or suggestions about my Privacy Policy, do not hesitate to contact me at atsu.popo.0224@gmail.com.

This privacy policy page was created at privacypolicytemplate.net and modified/generated by App Privacy Policy Generator

tfdsとかっていう、わりと使い勝手の悪い子

tensorflow_dataset 略して tfds ね。

これはtf.data.Datasetを元にして色々とtorch.Textみたいに出来るってやつなんだけど...

自然言語処理、もといテキスト処理に付いてはtorch.Textの方がよっぽど使い勝手が良いわ。

まあ、tensorflowはtensorflowで統一したほうが見通しが良いから、使うんだけどね。

やるのはこの2つ。

1.tfds.features.text.SubwordTextEncoder

2.tf.data.Dataset

1については、これは文章のリストからsentensepieceを使うやつね。

tokenizer = tfds.features.text.SubwordTextEncoder.build_form_corpus(corpus_generator , target_vocab_size)

target_vocab_size は 8000 ~ 32000 あれば十分だそうだから 213 ~ 215と言ったところね。

そうそう、tenorflow の tutorial で tfds.load() した data について、iterationして .numpy() としているわね。

これはただbyte型のデータに戻しているだけだから、自作のデータがあれば、それをそのままリストに変換してcorpus_generatorに入れれば大丈夫よ。

そのときにはstr型のまま,byte型に直さなくてもいいわ。

tokenizer = tfds.features.text.SubwordTextEncoder.load_from_file('path/to/tokenizer')
example = '今日はいい天気だね。一緒に遊びに行こうよ!'
print(tokenizer.encode(example))
#[126, 111, 7134, 132, 1, 169, 3048, 622, 11, 4]
print(tokenizer.decode(tokenizer.encode(example)))
#今日はいい天気だね。一緒に遊びに行こうよ!

2についてはdatasetを作るのに、tf.data.Dataset.from_tensor_slicesを使うわ。

dataset = tf.data.Dataset.from_tensor_slices(({'src': source_lines, 'tgt': target_lines}))

ここで、辞書からDatasetを作るには2重括弧の中に辞書を入れる必要があることに気をつけてね。

中身は勝手にtf.stringに変換されるから良いけど...でも、id化がmapを使ってそのまま変換というのが出来ないのよね。

こういったところが使い勝手が悪いのよ。

paddingした、データを用意する方法は2つ。

datasetに変換する前にid化とpaddingをするのか、変換した後でするかの2つよ。

1.dataset変換前にやる方法

#CONSTANTS
PAD = 0
SOS = tokenizer.vocab_size + 1
EOS = tokenizer.vocab_size + 2

#id化とpaddingね。
senteces = []
for sentence in train_data:
    sentenceの処理
    sentence = [SOS] + tokenizer.encode(sentence) + [EOS]
    sentences.append(sentence)
processed_sentences = tf.keras.preprocessing.sequence.pad_sequences(
                sentences, maxlen=MAX_LEN, padding='post')

#datasetの処理ね。
#questions, answers は上の処理をそれぞれに対して行えばいいわ。
dataset = tf.data.Dataset.from_tensor_slices((questions, answers))
dataset = dataset.cache()
dataset = dataset.shuffle(BUFFER_SIZE)
dataset = dataset.batch(BATCH_SIZE)
dataset = dataset.prefetch(tf.data.experimental.AUTOTUNE)

#後はモデルに入れればいいわ
model.fit(dataset, epochs=EPOCHS)

#でも、もしfrom_tensor_slicesに辞書を入れたときは別よ

dataset = tf.data.Dataset.from_tensor_slices(({
    'inputs': questions}, {'outputs': answers}))

def model(args):
    inputs = tf.keras.Input(..., name='inputs')
    ...
    outputs = tf.keras.layers....(..., name='outputs')
   return tf.keras.Model(inputs=[inputs], outputs=outputs)
#ちゃんと名前にdataを合わせてね。

2.Dataset変換後にやる方法

dataset = tf.data.Dataset.from_tensor_slices((questions, answers))

def encode(src, tgt):
    return ([SOS] + tokenizer.encode(src) + [EOS], [SOS] + tokenizer.encode(tgt) + [EOS]
    
def tf_encode(src, tgt):
    result_src, result_tgt = tf.py_function(encode, (src, tgt) , tf.int64)
    result_src.set_shape([None])
    result_tgt.set_shape([None])
    return result_src, result_tgt

dataset = datset.map(tf_encode)
dataの処理
dataset = dataset.chche()
dataset = dataset.shuffle(BUFFER_SIZE)
#ここがpadding化のところね
dataset = dataset.padded_batch(BATCH_SIZE)
dataset = dataset.prefetch(tf.data.experimental.AUTOTUNE)

まあ、どっちでも良いわね。

久しぶりね。

どうかしら。貴方達は元気にしてたかしら? 興味ないけど。

やはり、アウトプットも重要だと、どこかで見かけたから、ブログを再開するわね。 ただし、記事としてまとめるのではなく、あくまで個人の記録としてやっていくから、そこら辺は考慮しなさい。

tensorflow で学習するときにやっぱり model は保存しておきたいじゃない。 そんなときには2通りのやり方があるわ。本質的なものは変わらないけど、callbackで呼び出せるのかどうかが最大の違いね。

1.tf.keras.callbacks.ModelCheckpointを使う方法。 これは主に学習の途中と終了時に保存しておいて、評価とか学習の再開時に呼び出すのに使うわ。

2.model.save()を使う方法。 これはモデルの重みと最適化関数を保存する方法ね。これはモデルの再現を勝手にしてくれるのよ。 アーキテクチャーまで保存されるから、いろいろな用途で使えそうね。

1のやり方から見ていくわ。

#saving 
ckpt = tf.keras.callbacks.ModelCheckpoint(check_point_path, save_weights_only=True, verbose=1, save_best_only=Ture, periods=5)
model.fit(train_data, train_labels, epochs, validation_data, callbacks=[ckpt])

#loading
model.load_weights(check_point_path)

Arguments

-filepath モデルを保存するところ

-save_weights_only フルモデル(最適化関数とアーキテクチャーと重み)

-verbose 結果の出力

-save_best_only vadiation_loss が小さくなったときだけ保存

-periods 何回ごとのepochで保存するのか

2のやり方を見ていくわ

重みだけの保存時

#saving
model.save_weights('path/to/checkpoint')

#loading
model.load_weights('path/to/checkpoint')

モデル全体の保存時

#saving
model.save('path/to/model.h5')

#loading
new_model = tf.keras.models.load_model('path/to/model.h5')

仕上げのWakeOnLanよ。

さあ、最後にWakeOnLanを設定してしまうわよ。

前回に引き続き攻めのクライアント、受けのサーバーで説明していくわよ。

1.ローカル環境からの電源ON!

まず、受けのBIOSを開いて(電源をつけてからF2とか押していると出てくるわ)、"PCI/PCIEによる電源の起動"を"ON"にするわ。

そしたら、次のコマンドを実行してOSからもWake On Lan による電源の起動をONにするわ。

ifconfig

NICの名前とMACアドレスをひかえてね。en*** flags=~のen***がNICの名前でether の隣がMACアドレスよ。

sudo apt install ethtool
sudo ethtool -s en***  wol g 

で、有効化するわ。最後に確認するわ。

sudo  ethtool en***

上のコマンドを実行して、 Wake-on: g になっていれば、OKよ。

次にsystemdを利用して、自動で起動するようにするわ。

まず、systemの確認。

sudo system list-units

スクリプトを作成するわ。 /etc/systemd/system/wol@.service

[Unit]                                                                                                                             
Description=Wake-on-LAN for %i
Requires=network.target
After=network.target

[Service]
ExecStart=/sbin/ethtool -s %i wol g
Type=oneshot
User=root

[Install]
WantedBy=multi-user.target

そうしたら、前にやったようにsystemに登録してね。

sudo chmod 755 /etc/systemd/system/wol@.service
sudo systemctl daemon-reload
sudo systemctl start wol@.service
sudo systemctl enable wol@.service

最後に確認。

sudo systemctl list-units

そしたら、受けの方の電源を消してね。

攻めのほうにwakeonlanをインストールして、MACアドレスを使って接続するわ。

sudo apt install wakeonlan
wakeonlan MACアドレス

サスペンド状態からも復帰するから試してみてね。

2.遠隔操作でWake On Lan!

まずはポートの開放。ufw をつかって、1024以降の空いている好きな数字のポートをudpで開けてね。

...もう、手は貸さないわよ。

そしたら、ルーターにアクセスしてね。 ブラウザにアドレスを打ち込めば接続できるわ。 アドレスがわからなければ、

route -n

で、調べなさい。ゲートウェイの値があるところで一番上の行のところをみてね。

そうしたら、ルーターのポートをsshの方はTCPで、wakeonlanに使う方はUDPで開放してね。

あと、ルーターの設定からグローバルIPアドレスを控えておくこと。

さあ、受けの電源を消しなさい。用意はいいかしら。最後のコマンドよ。

wakeonlan -i グローバルIPアドレス -p wakeonlan用に開けたポート MACアドレス

電源はついたかしら?

長いあいだお疲れ様。また、会いましょう。

SSHの始まり、始まり

さあ、SSHの時間よ。結構、面倒くさいから覚悟しなさい。

わかりやすくするために、sshクライアントの方を攻め、sshサーバーの方を受けとしておくわ。

1.受けのPCにSSHサーバーをインストールして起動!

sudo apt install openssh-server
sudo systemctl enable ssh
sudo systemctl restart ssh

ちゃんと受けのポートも開いてあげないとね。

sudo ufw allow 22/tcp
sudo ufw reload

2.攻めのPCにSSHクライアントをインストールして繋ぐ!

sudo apt install openssh-client

ついに、合体するわ。あとで、sshのオプションもmanコマンドで見ておくこと。

ssh 受けのユーザー名@受けのIPアドレス 

成功したかしら? 次からは、公開鍵認証の設定に入っていくわ。

3.公開鍵認証の受けの設定

まずは、受けの設定から。/etc/ssh/sshd_configをルート権限で開いて設定していくわ。

コメントアウトを外して、値の方を変えてね。

Port 22 >> Port 空いている、かつ好きな1024以降の番号
PermitRootLogin no >> yes  

次にufwを使って、22番ポートを塞いで、さっきの決めたポートを開けてね。

やり方を忘れたとは言わせないわよ。

もし、忘れたなら、アナタが思う最も下等な動物の鳴き声で懇願しこの記事を見なさい。

https://pumayyaton.hatenablog.com/entry/2019/11/28/045011?_ga=2.157505023.451541375.1574873714-908569053.1574873714

4.公開鍵認証の攻めの設定

まずは鍵を作るわね。

ssh-keygen -t rsa

次に攻めの方にできた ~/.ssh/id_rsa.pub をSFTP接続で転送するわ。

sftp  -C -P 開けたポート 受けのユーザー名@受けのIPアドレス

そしたら、SFTPのssh環境に入るわ

sftp> lcd ~/.ssh
sftp> put ~/.ssh/id_rsa.pub
sftp> quit

そうして、ファイルを無事に遅れたら、受けの方でauthorized_keysに登録するわ

cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys

そうしたら、攻めの方でログインするわ。

ssh 受けのユーザー名@受けのIPアドレス -p 開けたポート

できた?最後にsshで接続して遠隔操作するわよ。

その前に、/etc/ssh/sshd_configの

PasswordAuthentication yes >> no

に設定しておいてね。

5.SSH Tunnelingによる遠隔操作

まず、受けのPCにsshで接続するわ。

ssh 受けのユーザー名@受けのIPアドレス -p 開けたポート -L 5900:localhost:5900

この時、攻めの方から攻めの方の5900ポートを通して、受けの方の5900ポートにデータを転送しているわ。

そうしたら、Remminaで接続するわね。

serverはlocalhost、userは受けの方の名前、passwordは同じく受けの方で設定したパスワードでいけるわ。

どうかしら?成功した?

最後に遠隔操作で電源をつけられるようにするから、楽しみにしていてね。

VNCの接続をしていくわよ

さて、今回はVNCをローカル環境で接続してくわね。

流れとしては以下の通りね。

1.x11vncのインストール

2.Remminaのインストール、起動、設定

3.Firewallのポート開放

4.x11vncとRemminaの接続

5.x11vncの自動起動設定

じゃあ、早速始めるわね。

x11vncのインストール

まずはこれでインストール。起動は後でね。

sudo apt update
sudo apt upgrade
sudo apt install x11vnc

パスワードだけ先に設定するわね。

x11vnc -storepasswd

で、パスワードを設定してちょうだい。保存先はデフォルトでOKよ。

Remminaのインストール、起動、設定

インストール

sudo apt install remmina remmina-common remmina-plugin-vnc

Remminaを起動するわね。 左上の+ボタンをクリックして、protocol をVNC、serverを192.168.xxx.xxx、ユーザー名をx11vncでサーバーを起動しているユーザー、パスワードをさっき設定したやつにしてね。

serverの確認なら

ifconfig

で、サーバーを起動するPCのIP Addressを見つけて、userの確認なら

cat /etc/passwd

で確認してね。

Firewallのポート開放

次にFirewall のポートをufwを使って開放するわ。VNC Server はDefaultで5900のポートを使用するわ。 まずはFirewallの設定確認。

sudo ufw status verbose

そしたら、ポートの開放。

sudo ufw allow 5900/tcp

5900のポートが空いたか、確認するわ。 確認したら、Firewallを再起動するわ。

sudo ufw reload

x11vncとRemminaの接続

そしたら、やっとx11vncを起動するわ。

x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /home/YourUserName/.vnc/passwd -rfbport 5900 -shared

Remminaの方を起動すれば接続されるはずね。うまくいけば、おめでとう。

x11vncの自動起動設定

OS起動時の自動起動を設定するのはSystemdを使った方法と、udevを使った方法があるのだけれど今回はSystemdを使った方法でやるわね。---ちなみに、/etc/rc.localを使った方法もあるのだけれど推奨はされていないわ。最も設定自体はとても簡単だから実験的にやってみたいならいいかもね。

まずは、システム全体の確認。

systemctl list-units

自動起動するスクリプトを作るわね。

/etc/systemd/system/x11vnc.service

[Unit]
Description=x11vnc Server Starting Operation
Reqires=display-manager.service

[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -rfbauth /home/YourUserName/.vnc/passwd -rfbport 5900 -forever -loop -noxdamage -repeat -shared
ExecStop=/usr/bin/x11vnc -R stop
Restart=on-failure

[Install]
WantedBy=multi-user.target

権限を与えて、

sudo chmod 755 /etc/systemd/system/x11vnc

システムに反映させるわ。

sudo systemctl daemon-reload
sudo systemctl start x11vnc.service
sudo systemctl enable x11vnc.service

そしたら、確認。

systemctl list-units

赤字でエラーが出力されていなかったら完了よ。お疲れ様。

次回はSSHで接続して、VNCを利用するわね。

と、思ったのだけれど

とりあえず、色々あって方針を変えたわ。

セキュリティー関係の話になっていくからよろしく。

はじめに、コンピューターの遠隔操作の話から始めるわね。

今回使う道具はこちら。

  1. VCN (x11vcn & remmina)

  2. SSH

  3. Wake On Lan

使用環境はクライアントもリモートも Linux Mint 19.1 よ。 Mintってかわいいじゃない?

今回使った道具の説明と目的について書いていくわね。

x11vcn

VCNってVirtual Network Computing のことね。違うOSで遠隔操作可能なソフトウエアのこと。今回はLinux2Linuxだから、あんまりメリットは無いのだけれど面白だから使ってみたわ。

VCNには操作する側にVNCクライアント、操作される側にVNCサーバーの合計2つのソフトが必要なのだけれど、x11vncはサーバーのほうね。もともと、LinuxMintにはVinoというVNCサーバーが入っていたのだけれど、デスクトップマネージャーがUbuntuのGDK、LinuxMintはLightDMと別れてしまって、VinoはGDK特化となってしまったから、LinuxMint19から入っていないわ。その代わりに使うのがx11vcnってわけ。

Remmina

こちらはVNCのクライアントのソフトね。GUIで結構わかりやすい画面が特徴よ。ただ、たまにフリーズするのが玉に瑕ね。

ufw

ufwはUmcoplicated Firewallのこと。 VNCSSHもポートが開いてないと使えないの。LinuxのポートはFireWallによって塞がれていて、iptablesで設定をするのだけれど結構めんどくさいのよね。 そのときに活躍するのがこれ。iptablesのラッパーで簡単にポートを開放できるわ。

ssh

sshはSecure Shellのこと。 残念ながら、VNC単体で使用していると通信データは丸見えになってしまうの。私はあの子とあの人以外にデータを覗かれるのは許す気は無いので、暗号化して送ることにしているの。 リモートサーバーにsshで接続した後にssh Tunnelingを利用して通信しているわ。 自身にVCNのデータを送ってから、そのデータをリモートにBindしているわ。

wakeonlan

Wake On Lan とは遠隔操作でPCの起動をする技術のこと。wakeonlanはそのためのソフトってわけ。

ethtool

Wake On Lan を行うにはPCの起動時にはBIOSの、OSの起動時にはOSのPCIE/PCEの設定をONにしないといけないわ。そのときにOSの方でPCIE/PCEの設定を確認できるのがこのアプリなの。

次回から実際に遠隔操作するための方法を書いていくわね。