Skip to main content

Posts

Showing posts from March, 2021

Tensorflow GPU Check

import tensorflow as tf with tf.device('/gpu:0'):       a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')       b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')       c = tf.matmul(a, b) with tf.Session() as sess: print(sess.run(c))

Make decompiling python code, generated from pyinstaller harder.

 General idea: Pyinstaller when creates an executable generates .pyc files of the functions or scripts. These .pyc files are easy to decompile. So a better security option is to use .pyd files. We need cython to generate .pyd files. Read: https://medium.com/analytics-vidhya/how-to-create-executable-of-your-python-application-from-linux-windows-mac-bcbcdd4603d4 https://programming.vip/docs/decompile-pyinstaller-packaged-exe-installation-package.html https://github.com/extremecoders-re/pyinstxtractor/ Step 1: creating an executable .exe file. Need: pyinstaller pip install pyinstaller then run: pyinstaller yourfile.py this will create an exe field in the dist directory - dist is the dir we are interested in not build but in the dist dir there are supporting files as well, to create a single executable file use: pyinstaller yourfile.py --onefile or  pyinstaller -F simpleprogram.py The problem: This exe can be decompiled to view source code. Decompiling: https://github.com/extremecoders-re/

Python Class Call

 https://www.geeksforgeeks.org/__call__-in-python/ __call__ in Python object() is shorthand for object.__call__() class Example:      def __init__(self):          print("Instance Created")             # Defining __call__ method      def __call__(self):          print("Instance is called via special method")     # Instance created  e = Example()     # __call__ method will be called  e()  Output : Instance Created Instance is called via special method class Product:      def __init__(self):          print("Instance Created")         # Defining __call__ method      def __call__(self, a, b):          print(a * b)     # Instance created  ans = Product()     # __call__ method will be called  ans(10, 20)  Output : Instance Created 200

Generators Python

https://www.programiz.com/python-programming/generator https://www.programiz.com/python-programming/methods/built-in/next Python Generators When a lot of data is present and you cannot load it into the memory at once Or if a function needs to maintain an internal state everytime it's called yield: yield is used in conjunction with generators Generators are functions They return lazy iterators.  lazy evaluation, or call-by-need, is an evaluation strategy which delays the evaluation of an expression until its value is needed (non-strict evaluation) and which also avoids repeated evaluations (sharing).  The sharing can reduce the running time of certain functions by an exponential factor over other non-strict evaluation strategies, such as call-by-name, which repeatedly evaluate the same function, blindly, regardless whether the function can be memoized. Iterators are objects that you can loop over like a list But unlike lists, lazy iterators do not store their contents in m

Staticmethod python

 Defined as @staticmethod def func(args, ...) @staticmethod  = decorator static methods do not have access to the properties of the class itself but you want them to belong to the class For example a utility function which might be useful for a class but you don't want it to interfere with other things in the class

Matplotlib Subplots

# fig = plt.figure() fig = plt.figure(figsize=(50,50)) ax = fig.add_subplot(1, 2, 1) plt.imshow(imgArray1, cmap='gray', vmin = 0, vmax = 255, interpolation='none', aspect='auto') #remove cmap to see colors ax.set_title('title1') ax = fig.add_subplot(1, 2, 2) plt.imshow(imgArray2, cmap='gray', vmin = 0, vmax = 255, interpolation='none') plt.show()  # # Uncomment to save image and see scores on title of image # picoutpath = os.path.join(self.outdir, 'lax_classify_jpg_out', labeldir) # os.makedirs(picoutpath, exist_ok=True) # picoutpath = os.path.join(picoutpath, filename.replace('.npy', '.jpg')) # plt.imshow(imgarr, cmap='gray', interpolation=None) # plt.title(f' [ GT:{gtrth_x} PD:{predc_x} PRB:{ma_score:.2f} ]') # plt.savefig(picoutpath, dpi=200) # plt.close() fig, axs = plt.subplots(1, 2, dpi=200)     i = 0      im = axs[i].imshow(img, cmap='gray', interpolation=None)     axs[i].set_title(f&