Skip to content

Instantly share code, notes, and snippets.

View zaidalyafeai's full-sized avatar
:octocat:
Working from home

Zaid Alyafeai zaidalyafeai

:octocat:
Working from home
View GitHub Profile
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
<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>
$$\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}$$
function predict(imgData) {
return tf.tidy(() => {
//get the prediction
const gImg = model.predict(preprocess(imgData))
//post process
const postImg = postprocess(gImg)
return postImg
})
}
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])
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);
<script src="tf.min.js"> </script>
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)
!mkdir web_model
!mkdir saved_model
!mkdir XOR
os.chdir('XOR')