JoomlaのURLはデフォルトではとても複雑で、SEO Friendly URLの設定をすることでだいぶすっきりするが、それでもindex.phpや数字が残る。これを取り除く。
システム→グローバル設定
グローバル設定 → サイト
→ フレンドリURL ... はい
→ URLリライトの使用 ... はい
URLリライトのために、サーバーに置いてある「htaccess.txt」のファイル名を「.htaccess」に変更
※もしInternal Server Error が出るなら以下を参照
Joomla!備忘録
.htaccess にファイル名を変更した内容を以下の部分を書き加えて下さい。
14行目(Joomla!3.4.1 オリジナルの場合)
Options +FollowSymlinks
の先頭に(#)を追加して保存して下さい。
https://joomla.mdeps.com/nmerror/urlrwerr.html
記事→ 統合
→ URLルーティング ... モダン
→ URLからIDを削除する ... はい
https://www.joomshaper.com/blog/making-joomla-site-seo-friendly-by-removing-id-from-urls
https://www.joomlabeginner.com/blog/tutorials/116-how-to-remove-ids-and-numbers-from-joomla-urls
ただ Object → Convert To → Curve だけではカーブオブジェクトにはなっても曲線にならない。
カーブにしてから種類をBezierカーブに変更する。
F3 → Curve → Set Spline Type → Bezier
Bezierではこれでもまだ曲線にならない。[v]を押し、ハンドルの種類をAlignedにすることで曲線になる。
以下のような関数があるとする。
float divide(const float a, const float b) { return a / b; }
諸事情によりテンプレート化を行ったとする。
template<typename T> auto divide(const T a,const T b) { return a/b; }
この時、整数が入力されたときにもまともな答えが出てほしい。
template<typename T> auto divide(const T a,const T b) { return a/b; } int main() { float a = divide(5.0,10.0); // a == 0.5 float b = divide(5,10); // b == 0.0 printf("%lf %lf", a,b); getchar(); }
こんなテンプレートを定義する
//入力が浮動小数点の時はそのまま返す //それ以外の時はfloatを返す template<typename T, bool isint>struct IsRealT; template<typename T>struct IsRealT<T, true> { using type = T; }; template<typename T>struct IsRealT<T, false> { using type = float; }; //入力が整数ならfloatを返す template<typename T> struct RealIfInt { using type = typename IsRealT<T, std::is_floating_point<T>::value>::type; };
内部でキャストする。なんで普通にdoubleでキャストしないでテンプレートで切り分けなんかするのか、そもそもこの関数自体doubleで受け取ればいいんじゃないのか、と思うのだが、型が違うと随所でwarningが出て読みづらくなるというのがある。
template<typename T> auto divide(const T a, const T b) { using realT = typename RealIfInt<T>::type; return static_cast<realT>(a) / static_cast<realT>(b); } int main() { auto a = divide(5.0, 10.0); // a == 0.5 auto b = divide(5, 10); // b == 0.5 printf("%lf %lf", a, b); getchar(); }
正直、エラーの読みづらさをいうならテンプレートを使った時点で大変なことになるので説得力は微妙。
PPMのような3byteのデータを扱うと画素のコピーとか素直にできない。あとループ時のメモリ計算が面倒くさい。sizeofでとれないので*3しなければならないが、PGM等に変えるとcharなので*3を外さなければいけない。
かといって専用構造体を作るとそれはそれで使いにくい。そんなときNByteのデータを扱うようなデータ型が欲しい。
#include<array> #include<cstring> template<size_t SIZE> class NByteData { std::array<unsigned char, SIZE> m_data; public: using ThisT = NByteData<SIZE>; unsigned char* data() { return m_data.data(); }
ThisT& operator=(const ThisT& t) { for (size_t i = 0; i < m_data.size(); i++) { m_data[i] = t.m_data[i]; } return *this; }
bool operator==(const ThisT& t)const { for (size_t i = 0; i < SIZE; i++) { if (m_data[i] != t.m_data[i]) return false; } return true; }
bool operator!=(const ThisT& t)const { return !this->operator==(t); }
NByteData() {}
NByteData(const ThisT& src) { this->operator=(src); }
NByteData(std::initializer_list<unsigned char> inits) { unsigned char* p = m_data.data(); for (auto uc : inits) { *p = uc; ++p; } }
};
#include <iostream> #include<vector> #pragma warning(disable:4996) #include "NByteData.hpp"
// 3byte rgbの画素作成 NByteData<3> uc3rgb( unsigned char r, unsigned char g, unsigned char b) { return NByteData<3>({r,g,b}); }
void pnmP3_Write(const char* const fname, const int vmax, const int width, const int height, const unsigned char* const p);
int main() { std::vector<NByteData<3> > rgb_ppm; int width = 255; int height = 30; rgb_ppm.resize(width*height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { rgb_ppm[y*width+x] = uc3rgb(x, 0, 0); } } pnmP3_Write(R"(C:\data\rgb.ppm)", 255, width, height, rgb_ppm.begin()->data()); }
///////////////////////////////////////////////////////////////// //! @brief PPM(RGB各1byte,カラー,テキスト)を書き込む //! @param [in] fname ファイル名 //! @param [in] vmax 全てのRGBの中の最大値 //! @param [in] width 画像の幅 //! @param [in] height 画像の高さ //! @param [in] p 画像のメモリへのアドレス //! @details RGBRGBRGB....のメモリを渡すと、RGBテキストでファイル名fnameで書き込む void pnmP3_Write(const char* const fname, const int vmax, const int width, const int height, const unsigned char* const p) { // PPM ASCII FILE* fp = fopen(fname, "wb"); fprintf(fp, "P3\n%d %d\n%d\n", width, height, vmax); size_t k = 0; for (size_t i = 0; i < (size_t)height; i++) { for (size_t j = 0; j < (size_t)width; j++) { fprintf(fp, "%d %d %d ", p[k * 3 + 0], p[k * 3 + 1], p[k * 3 + 2]); k++; } fprintf(fp, "\n"); } fclose(fp); }
#include <iostream> #include<vector> #pragma warning(disable:4996) #include "NByteData.hpp"
// 1byte グレイスケールの画素作成 NByteData<1> uc1gray(unsigned char gray) { return NByteData<1>({gray}); }
void pnmP2_Write(const char* const fname, const int vmax, const int width, const int height, const unsigned char* const p);
int main() { std::vector<NByteData<1> > gray_pgm; int width = 255; int height = 30; gray_pgm.resize(width*height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { gray_pgm[y*width+x] = uc1gray(x); } } pnmP2_Write(R"(C:\data\gray.pgm)", 255, width, height, gray_pgm.begin()->data()); }
///////////////////////////////////////////////////////////////// //! @brief PPM(RGB各1byte,カラー,テキスト)を書き込む //! @param [in] fname ファイル名 //! @param [in] vmax 全てのRGBの中の最大値 //! @param [in] width 画像の幅 //! @param [in] height 画像の高さ //! @param [in] p 画像のメモリへのアドレス //! @details RGBRGBRGB....のメモリを渡すと、RGBテキストでファイル名fnameで書き込む void pnmP2_Write(const char* const fname, const int vmax, const int width, const int height, const unsigned char* const p) { // PPM ASCII FILE* fp = fopen(fname, "wb"); fprintf(fp, "P2\n%d %d\n%d\n", width, height, vmax); size_t k = 0; for (size_t i = 0; i < (size_t)height; i++) { for (size_t j = 0; j < (size_t)width; j++) { fprintf(fp, "%d ", p[k]); k++; } fprintf(fp, "\n"); } fclose(fp); }
Kerasでget_weights , set_weights。もうちょっと複雑なモデルで動作確認する。
import tensorflow as tf import numpy as np # Define the model. model = tf.keras.models.Sequential([ tf.keras.layers.Input(shape=(1,)), tf.keras.layers.Dense(3, activation='linear'), tf.keras.layers.Dense(2, activation='linear'), tf.keras.layers.Dense(1, activation='linear') ]) print("----------------")
# レイヤー0の重み取得 L0w = model.layers[0].get_weights() L1w = model.layers[1].get_weights() L2w = model.layers[2].get_weights()
# 取得時の重みを表示 print("default weight 0", L0w ) print("default weight 1", L1w ) print("default weight 2", L2w )
# 重みを書き換え L0w[0][0][0] = 1.0 L0w[0][0][1] = 2.0 L0w[0][0][2] = 3.0 L1w[0][0][0] = 4.0 L1w[0][0][1] = 5.0 L1w[0][1][0] = 6.0 L1w[0][1][1] = 7.0 L1w[0][2][0] = 8.0 L1w[0][2][1] = 9.0 L2w[0][0][0] = 10.0 L2w[0][1][0] = 11.0
print("----------------") # 重みをモデルにセット model.layers[0].set_weights(L0w) model.layers[1].set_weights(L1w) model.layers[2].set_weights(L2w) # モデルの重みが更新されていることを確認 print("edited weight 0", model.layers[0].get_weights() ) print("edited weight 1", model.layers[1].get_weights() ) print("edited weight 2", model.layers[2].get_weights() ) print("----------------") print( " 0番 output の値" ) for n in range(0,5): predict_y = model.predict( np.array( [[n]] ) ) print( n , predict_y[0][0] )
model.layers[].get_weights()はレイヤーごと、ノードごとに重みを取ってくる。ノードとノードを繋ぐ線をエッジというが、重みはいわばエッジが持っているので、「現在のノード」→「次のノード」のペアで対象の重みの位置を表せる。
[0][そのレイヤーのノード番号][次のレイヤーのノード番号]
以下のように重みを書き換えてみる。
# 重みを書き換え L0w[0][0][0] = 1.0 L0w[0][0][1] = 2.0 L0w[0][0][2] = 3.0 L1w[0][0][0] = 0.0 L1w[0][0][1] = 1.0 L1w[0][1][0] = 0.0 L1w[0][1][1] = 0.0 L1w[0][2][0] = 0.0 L1w[0][2][1] = 1.0 L2w[0][0][0] = 3.0 L2w[0][1][0] = 4.0
結果、重みは以下のように設定されている。
バイアスは今回は0ということにして、伝達関数はLinearにしているので、入力値はノードに入ったら重みを掛けられてそのまま次のノードへ行く。重みが0だと0になるので以下のような足し算になり、結果値が16倍される関数になる。
Kerasで作ったモデルのノードそれぞれの重みを取得するにはget_weights、設定するにはset_weightsを使用する。
import tensorflow as tf import numpy as np # Define the model. model = tf.keras.models.Sequential([ tf.keras.layers.Input(shape=(1,)), tf.keras.layers.Dense(2, activation='linear') ]) print("----------------") # レイヤー0の重み取得 L0w = model.layers[0].get_weights() # 取得時の重みを表示 print("default weight 0", L0w ) print("----------------") # 重みを書き換え L0w[0][0][0] = 1.0 L0w[0][0][1] = 2.0 # 重みをモデルにセット model.layers[0].set_weights(L0w) # モデルの重みが更新されていることを確認 print("edited weight 0", model.layers[0].get_weights() ) print("----------------") print( " 0番 output の値" ) for n in range(0,5): predict_y = model.predict( np.array( [[n]] ) ) print( n ,"→ f →" , predict_y[0][0] ) print("--------------------") print( " 1番 output の値" ) for n in range(0,5): predict_y = model.predict( np.array( [[n]] ) ) print( n ,"→ f →" , predict_y[0][1] )
まずモデルを作る。
# Define the model. model = tf.keras.models.Sequential([ tf.keras.layers.Input(shape=(1,)), tf.keras.layers.Dense(2, activation='linear') ])
次にモデルの重みを取得する
# レイヤー0の重み取得 L0w = model.layers[0].get_weights()
するとどうやら、図のような関係になっているらしい。
ので、書き換えてモデルを更新する。
# 重みを書き換え L0w[0][0][0] = 1.0 L0w[0][0][1] = 2.0 # 重みをモデルにセット model.layers[0].set_weights(L0w)
するとこんな関係になる。
説明というか現状までの理解については次回以降にして、今はとにかく結果が得られるコードが欲しいのでそれらしい物を書いた。
import tensorflow as tf import numpy as np from tensorflow.keras.optimizers import RMSprop # モデル作成 # Define the model. model = tf.keras.models.Sequential([ tf.keras.layers.InputLayer(input_shape=(2,)), # 入力層 要素数1、内容「2」のタプル tf.keras.layers.Dense(units=4, activation='sigmoid'), tf.keras.layers.Dense(units=4, activation='sigmoid'), tf.keras.layers.Dense(units=1, activation='linear') # 出力層 1出力。1出力の時はsoftmaxは使えない ]) model.compile( optimizer=RMSprop(), loss='mse' ) # トレーニング用入力 XY = np.array( [[0.0,0.0], [0.0,1.0], [1.0,0.0], [1.0,1.0]] ) # 正解データ T = np.array( [[0.0], [1.0], [1.0], [0.0]] ) # トレーニング model.fit(XY, T, epochs=3000, batch_size=4) print("------------------------------") # 出力値をしきい値処理 threshold = 0.5 # 検証用データをモデルに入力し、出力(予測値)を取り出す predict_y = model.predict( np.array( [[0,0]] ) ) print( predict_y , (predict_y > threshold).astype(np.int) ) predict_y = model.predict( np.array( [[1,0]] ) ) print( predict_y , (predict_y > threshold).astype(np.int) ) predict_y = model.predict( np.array( [[0,1]] ) ) print( predict_y , (predict_y > threshold).astype(np.int) ) predict_y = model.predict( np.array( [[1,1]] ) ) print( predict_y , (predict_y > threshold).astype(np.int) )
import tensorflow as tf import numpy as np from tensorflow.keras.optimizers import RMSprop # モデル作成 # Define the model. model = tf.keras.models.Sequential([ tf.keras.layers.InputLayer(input_shape=(2,)), # 入力層 要素数1、内容「2」のタプル tf.keras.layers.Dense(units=4, activation='sigmoid'), tf.keras.layers.Dense(units=4, activation='sigmoid'), tf.keras.layers.Dense(units=2, activation='softmax') # 出力層 softmaxの時は2個以上の出力 ]) model.compile( optimizer=RMSprop(), loss='mse' ) # トレーニング用入力 XY = np.array( [[0.0,0.0], [0.0,1.0], [1.0,0.0], [1.0,1.0]] ) # 正解データ (One Hot表現) T = np.array([[0.0, 1.0], [1.0, 0.0], [1.0, 0.0], [0.0, 1.0]]) # トレーニング model.fit(XY, T, epochs=3000, batch_size=4) print("------------------------------") # 出力値をしきい値処理 threshold = 0.5 # 検証用データをモデルに入力し、出力(予測値)を取り出す predict_y = model.predict( np.array( [[0,0]] ) ) print( predict_y , (predict_y > threshold).astype(np.int) ) predict_y = model.predict( np.array( [[1,0]] ) ) print( predict_y , (predict_y > threshold).astype(np.int) ) predict_y = model.predict( np.array( [[0,1]] ) ) print( predict_y , (predict_y > threshold).astype(np.int) ) predict_y = model.predict( np.array( [[1,1]] ) ) print( predict_y , (predict_y > threshold).astype(np.int) )
Denseを調べます
http://marupeke296.com/IKDADV_DL_No7_dense.html
ご注文は TensorFlow 2.x ですか??
https://hmx.hatenablog.jp/entry/2020/04/26/000000
光軒の集い
https://www.kouken-party.info/2017/10/25/python%E3%81%A8keras%E3%81%A7xor/
kerasでOne-hotのラベルを作成する
https://qiita.com/okj15/items/f081ac0928540f1579b5
【Python/Keras】ニューラルネットで論理演算(XOR)の学習
https://algorithm.joho.info/machine-learning/python-keras-neural-network-and-or/
Cannot train a neural network solving XOR mapping
https://stackoverflow.com/questions/34311586/cannot-train-a-neural-network-solving-xor-mapping
この記事の目的はとにかく検索すると1.x系列の情報がまずヒットするので手の届くところに最小限の2.x系列で動くサンプルを置いておく事にある。
import tensorflow as tf a = tf.constant(10.1, dtype=tf.float32, name="a") b = tf.constant(20.2, dtype=tf.float32, name="b") c = tf.Variable(30.3, dtype=tf.float32, name="c") d = tf.Variable(40.4, dtype=tf.float32, name="d") # @tf.functionを付けると関数のような形で計算グラフを書ける @tf.function def f(): divop = tf.divide(a,b,name="a-div-b") addop = tf.math.add(divop,c,name="div-add-c") d.assign(addop,name="d-assign-add") # ここでrun f() tf.print(d)
import tensorflow as tf a = tf.constant(10.1, dtype=tf.float32, name="a") b = tf.constant(20.2, dtype=tf.float32, name="b") c = tf.Variable(30.3, dtype=tf.float32, name="c") d = tf.Variable(40.4, dtype=tf.float32, name="d") # @tf.functionを使わない場合。 divop = tf.divide(a,b,name="a-div-b") addop = tf.math.add(divop,c,name="div-add-c") d.assign(addop,name="d-assign-add") tf.print(d)
@tf.functionで書かないTensorBoard用出力の方法がどうしてもわからなかったのでとりあえず使ったもの。
この例ではグラフをカレントディレクトリの./output/に出力する
import tensorflow as tf import os
logdir = './output' writer = tf.summary.create_file_writer(logdir)
################################### a = tf.constant(10.1, dtype=tf.float32, name="a") b = tf.constant(20.2, dtype=tf.float32, name="b") c = tf.Variable(30.3, dtype=tf.float32, name="c") d = tf.Variable(40.4, dtype=tf.float32, name="d") @tf.function def f(): divop = tf.divide(a,b,name="a-div-b") addop = tf.math.add(divop,c,name="div-add-c") d.assign(addop,name="d-assign-add") ###################################
with writer.as_default(): tf.summary.graph(f.get_concrete_function().graph) writer.close()
以下のコマンドでtensorBoardを起動し、ブラウザでhttp://localhost:6006/ を開く。
なぜかconstantの名前が消えてx,yになる上にVariableは表示すらされない。散々調べたが表示する方法が見つからなかった。
計算グラフの表示に関してはtf.summary.trace_on(graph=True,profiler=False) でもできる。ちなみにprofiler=Trueにしたら私の環境ではエラーが出たので試せていない。
import tensorflow as tf import os logdir = './output' writer = tf.summary.create_file_writer(logdir)
tf.summary.trace_on(graph=True,profiler=False)
################################### a = tf.constant(0.01, dtype=tf.float32, name="a") s = tf.Variable(0.0, dtype=tf.float32, name="s") v = tf.Variable(0.0, dtype=tf.float32, name="v") @tf.function def f(): s.assign_add(a) v.assign(tf.sin(s)) ################################### f() # 一度は計算グラフを走らせないと出力できない with writer.as_default():
tf.summary.trace_export("summary", step=0, profiler_outdir="./output")
tf.summary.trace_off()
writer.close()
tensorflowはニューラルネットワークを組むために作られた計算グラフ作成ツールであり(という理解をしている)、同じ計算グラフを何度もrunさせて重みを調整していく事を想定しているので、繰り返した場合の値の変化をtensorBoardで確認してみる。
import tensorflow as tf import os logdir = './output' writer = tf.summary.create_file_writer(logdir) ################################### a = tf.constant(0.01, dtype=tf.float32, name="a") s = tf.Variable(0.0, dtype=tf.float32, name="s") v = tf.Variable(0.0, dtype=tf.float32, name="v") @tf.function def f(): s.assign_add(a) v.assign(tf.sin(s)) ################################### with writer.as_default(): for STEP in range(1000): # 1000 回繰り返し f() # 計算グラフ実行 tf.summary.scalar("s",s,step=STEP) # scalarを出力するときは、何回目のループなのかを表すstepを指定しなければいけない tf.summary.scalar("v",v,step=STEP) writer.flush() writer.close()
Blender 2.9からBlender 2.79へデータを変換する方法。Blender 2.93側でCtrl+C(コピー)→Blender 2.79側でCtrl+V(貼り付け)をすれば2.79に取り込むことができる。
Blender 2.7系はデフォルトでBlender RenderだったりするのでうっかりCyclesにし忘れるとレンダリングできないので注意。
Editモードで[U]キーを押してunwrapする
以下のHDRIをダウンロードしてWorldに適用する。その後、レンダリング結果の背景が空だけになるようにカメラと背景の関係を調整する
https://hdrihaven.com/hdri/?h=snowy_park_01
https://www.textures.com/download/PBR0234/133290