How to create python application like pipenv or django-admin or pytest etc...?
I am writing a pip module that has to run from command line. I need some steps to create python application.
Thanks in advance.
See also questions close to this topic
Converting a numpy operation to output of tensorflow layer
I am trying to convert a numpy layer using tensorflow and keras
# output from model op_from_model = <tf.Tensor '1_conv_1x1_parts/BiasAdd:0' shape=(?, 64, 64, 16) dtype=float32> # Numpy style - from scipy.ndimage import gaussian_filter, maximum_filter import numpy as np lst = np.zeros([16,3]) for i in range(maps.shape[-1]): _map = maps[:,:,i] _map = gaussian_filter(_map, sigma=0.3) _nmsPeaks = non_max_supression(_map, windowSize=3, threshold=1e-6) y, x = np.where(_nmsPeaks == _nmsPeaks.max()) if len(x) > 0 and len(y) > 0: lst[:,i] = [int(x), int(y), _nmsPeaks[y, x]] def non_max_supression(map, windowSize, threshold): under_th_indices = plain < threshold plain[under_th_indices] = 0 return plain * (plain == maximum_filter(plain, footprint=np.ones((windowSize, windowSize)))) #TF layer style # adapted from here https://stackoverflow.com/questions/52012657/how-to-make-a-2d-gaussian-filter-in-tensorflow from keras import backend as K import tensorflow as tf def gaussian_kernel(size: int, mean: float, std: float): d = tf.distributions.Normal(mean, std) vals = d.prob(tf.range(start = -size, limit = size + 1, dtype = tf.float32)) gauss_kernel = tf.einsum('i,j->ij', vals, vals) return gauss_kernel / tf.reduce_sum(gauss_kernel) gauss_kernel = gaussian_kernel(5, 0.44, 0.5) # have to set correct params here gauss_kernel = gauss_kernel[:, :, tf.newaxis, tf.newaxis] filt_op = tf.nn.conv2d(np.expand_dims(np.expand_dims(np.array(map[:,:,0] , dtype = np.float32), axis=0),axis=3), gauss_kernel, strides=[1, 1, 1, 1], padding="SAME") indices = tf.image.non_max_suppression(filt_op, flatten_scores, max_output_size=10, iou_threshold=0.3)
How can I get the lst from the filtered indices as output of the model? I am using keras and TF.
Django - Too slow database record read
I have a database with about 1500 records about one class. I'm also using jQuery Datatables to list the records.
But, it is very very slow. Even reducing the number of records to 100 it takes about 20~45 seconds to fully load a page. Doing the same select to find all 1500 records directly on database takes only 1 second.
As I am using jQuery DataTables to paginate and search the values, is there a way to improve this loading table time?
create variables from strings in list
New to Python here. I want to create new variables with names taken from strings in a list. (I looked around and there were a couple questions with similar names, but it looked like they were trying to do different things.)
Here is a simplified example to show what I'm trying to do:
mylist = ["a", "b", "c", "d"] for item in mylist: item = input("What do you want " + str(item) + " to be defined as?")
If I run through it and enter what I want each of the variables I am trying to create to be...
What do you want a to be defined as?"apple" What do you want b to be defined as?"bob" What do you want c to be defined as?"cat" What do you want d to be defined as?"dog"
I am TRYING to do the equivalent of defining
a = "apple" b = "bob" c = "cat" d = "dog"
But, when I check to see if it worked, I get:
NameError: name 'a' is not defined
(Or, if I could rename an already-defined variable X with a name pulled from a list, I could make that work to do what I want also. It's just the creating a variable name from a string within a list part that is eluding me.)
Also, note: I am NOT trying to change the entries in mylist (i.e. to change it to mylist = ["apple", "bob", "cat", "dog"]). I'm just trying to pull names from mylist to use as variables to do other things elsewhere. I want mylist to stay just ["a", "b", "c", "d"].