Categories
Mastering Development

Fast way to remove array of specific row values from 2D numpy array

I have a 2D array like this: a = np.array([[25, 83, 18, 71], [75, 7, 0, 85], [25, 83, 18, 71], [25, 83, 18, 71], [75, 48, 8, 43], [ 7, 47, 96, 94], [ 7, 47, 96, 94], [56, 75, 50, 0], [19, 49, 92, 57], [52, 93, 58, 9]]) and I want to […]

Categories
Mastering Development

Speed in Matlab vs. Julia vs. Fortran

I am playing around with different languages to solve a simple value function iteration problem where I loop over a state-space grid. I am trying to understand the performance differences and how I could tweak each code. For posterity I have posted full length working examples for each language below. However, I believe that most […]

Categories
Raspberry Pi User Help

PiCamera V1.3: Long Operation Time Effects

I have this simple code, with picamera.PiCamera(resolution=(2592, 1944), framerate=15, sensor_mode=2) as camera: camera.iso = 400 # Wait for automatic gain control to settle sleep(2) # Change to 2 seconds for calibration camera.shutter_speed = 66127 camera.exposure_mode = ‘off’ # CALIBRATION PURPOSES g = camera.awb_gains camera.awb_mode = ‘off’ camera.awb_gains = g with picamera.array.PiRGBArray(camera) as output: camera.capture(output, format=’bgr’) […]

Categories
Mastering Development

Reshaping a circular buffer to the thrid dimension

We can reshape a regular matrix to the third dimension using: julia> data = rand(4,2) 4×2 Array{Float64,2}: 0.89585 0.328315 0.77878 0.619666 0.232389 0.132091 0.48543 0.829476 julia> reshape(data, 4, 1, 2) 4×1×2 Array{Float64,3}: [:, :, 1] = 0.895850499952602 0.7787804133322247 0.23238945917674037 0.4854297310447009 [:, :, 2] = 0.3283154491436233 0.6196660556881552 0.13209084702809903 0.8294762758800456 But if using CircularBuffer we get an […]

Categories
Mastering Development

How to show the Color image feed from kinect using freenect2-python

I’m using freenect2-python to read frames from kinectv2. Following is my code: from freenect2 import Device, FrameType import cv2 import numpy as np def callback(type_, frame): print(f'{type_}, {frame.format}’) if type_ is FrameType.Color: # FrameFormat.BGRX rgb = frame.to_array().astype(np.uint8) cv2.imshow(‘rgb’, rgb[:,:,0:3]) device = Device() while True: device.start(callback) if cv2.waitKey(1) & 0xFF == ord(‘q’): device.stop() break The color […]

Categories
Linux Mastering Development

Executable does not work if run outside its folder

I have an already structured SDK folder where I have my project. Program works as expected if I do: cd /home/user/Documents/Camera/ProjectCamera/linux64/proj make cd /home/user/Documents/Camera/ProjectCamera/linux64/lib ./Camera Now I want to run the executable from outside ‘lib’ folder but program does not work if I do. I can run the executable but the program returns errors in […]

Categories
Mastering Development

Pytorch: loss is not changing

I created a neural network in PyTorch. My loss function is a weighted negative log-likelihood. The weights are determined by the output of my neural network and must be fixed. It means the weights depend on the output of the neural network but must be fixed so the network only calculates the gradient of log […]

Categories
Mastering Development

plotting streamplot is so slow in python3

I am using Anaconda, and I think this problem is even before I use Anaconda. Everytime I want to plot streamline with basemap, it takes a very long time to plot one figure. Here is an example: import netCDF4 as nc import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.basemap import Basemap fuv = […]

Categories
Mastering Development

How to make custom code in python utilize GPU while using Pytorch tensors and matrice functions

I’ve created a CNN from scratch only using Pytorch tensors and matrix operation functions in the hope of utilizing GPU. To my surprise, the GPU stays 0% utilized and my training doesn’t seem to be faster than running on my cpu. CODE: import operator from pathlib import Path from IPython.core.debugger import set_trace from fastai import […]

Categories
Mastering Development

Training accuracy remains constant after applying a generator

I am working on image segmentation with UNet. I started with single-band image and trained the model with below code: from glob import glob from PIL import Image from sklearn.model_selection import train_test_split import matplotlib.pyplot as plt import numpy as np import tensorflow as tf from tensorflow.python.keras import layers from tensorflow.python.keras import losses from tensorflow.python.keras import […]