This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t = "blah blah" | |
t = araby.strip_tashkeel(t) #remove tashkeel | |
t = re.sub(r'([-؟،.!;:])', ' \\1 ', t) #add spaces between special charaacters | |
t = re.sub(r'([^\s\w\-؟،.!;:])+', '', t) #remove all special characters except some | |
t = re.sub(r'[³ـ¼]', '', t) #explecitly remove some special characters | |
t = re.sub('[a-zA-z]', '', t) #remove english litters |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs/dist/tf.min.js"> </script> | |
<script src="https://cdn.jsdelivr.net/npm/ua-parser-js@0/dist/ua-parser.min.js"></script> | |
<img id="img" src="https://i.imgur.com/gQLIJkN.png" crossorigin="" style = 'display:none;' /> | |
<table> | |
<td>Browser</td> | |
<td id = 'browserName'></td> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$$\begin{array}{|c|c|} | |
\hline | |
\textbf{$f(x)$} & \textbf{$f'(x)$} \\ | |
\hline | |
\sin(x) & \cos(x)\\ | |
\cos(x) & - \sin(x)\\ | |
\log(x) & \frac{1}{x}\\ | |
e^x & e^x\\ | |
\hline | |
\end{array}$$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function predict(imgData) { | |
return tf.tidy(() => { | |
//get the prediction | |
const gImg = model.predict(preprocess(imgData)) | |
//post process | |
const postImg = postprocess(gImg) | |
return postImg | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function postprocess(tensor){ | |
return tf.tidy(() => { | |
//normalization factor | |
const scale = tf.scalar(0.5); | |
//unnormalize and sqeeze | |
const squeezed = tensor.squeeze().mul(scale).add(scale) | |
//resize to canvas size | |
const resized = tf.image.resizeBilinear(squeezed, [w, h]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function preprocess(imgData) { | |
return tf.tidy(() => { | |
//convert to a tensor | |
const tensor = tf.fromPixels(imgData).toFloat() | |
//resize | |
const resized = tf.image.resizeBilinear(tensor, [256, 256]) | |
//normalize | |
const offset = tf.scalar(127.5); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="tf.min.js"> </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def transform(image, scale): | |
r = image | |
if a.flip: | |
r = tf.image.random_flip_left_right(r, seed=seed) | |
# area produces a nice downscaling, but does nearest neighbor for upscaling | |
# assume we're going to be doing downscaling here | |
r = tf.image.resize_images(r, [scale[0], scale[0]], method=tf.image.ResizeMethod.AREA) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!mkdir web_model | |
!mkdir saved_model |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!mkdir XOR | |
os.chdir('XOR') |
NewerOlder