Python scipy.pi() Examples

The following are 30 code examples of scipy.pi(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module scipy , or try the search function .
Example #1
Source File: heatTransfer.py    From pychemqt with GNU General Public License v3.0 6 votes vote down vote up
def h_tube_Condensation_Traviss(fluid, Di, X):
    """ref Pag 558 Kakac: Boiler..."""
    G = fluid.caudalmasico*4/pi/Di**2
    Re = Di*G*(1-fluid.x)/fluid.Liquido.mu
    F1 = 0.15*(1/X+2.85*X**-0.476)
    if Re < 50:
        F2 = 0.707*fluid.Liquido.Prandt*Re
    elif Re < 1125:
        F2 = 5*fluid.Liquido.Prandt+5*log(1+fluid.Liquido.Prandt*(0.0964*Re**0.585-1))
    else:
        F2 = 5*fluid.Liquido.Prandt+5*log(1+5*fluid.Liquido.Prandt)+2.5*log(0.0031*Re**0.812)

    return fluid.Pr*Re**0.9*F1/F2


# Heat Exchanger design methods 
Example #2
Source File: LoadData_V2.py    From Autopilot with MIT License 6 votes vote down vote up
def return_data():

    X = []
    y = []
    features = []

    with open(TRAIN_FILE) as fp:
        for line in islice(fp, LIMIT):
            path, angle = line.strip().split()
            full_path = os.path.join(DATA_FOLDER, path)
            X.append(full_path)
            # using angles from -pi to pi to avoid rescaling the atan in the network
            y.append(float(angle) * scipy.pi / 180)

    for i in range(len(X)):
        img = plt.imread(X[i])
        features.append(preprocess(img))

    features = np.array(features).astype('float32')
    labels = np.array(y).astype('float32')

    with open("features", "wb") as f:
        pickle.dump(features, f, protocol=4)
    with open("labels", "wb") as f:
        pickle.dump(labels, f, protocol=4) 
Example #3
Source File: heatExchanger.py    From pychemqt with GNU General Public License v3.0 6 votes vote down vote up
def _hAnnulli(self, fluidAnnulli):
        """Calculate convection heat transfer coefficient in annulliside"""
        a = self.Dee/self.De
        dh = self.Dee-self.De

        rho = fluidAnnulli.Liquido.rho
        mu = fluidAnnulli.Liquido.mu
        k = fluidAnnulli.Liquido.k
        v = fluidAnnulli.Q*4/pi/(self.Dee**2-self.De**2)
        re = Re(D=dh, V=v, rho=rho, mu=mu)
        self.VAnnulli = unidades.Speed(v)
        self.rhoAnnulli = rho
        self.ReAnnulli = unidades.Dimensionless(re)
        pr = fluidAnnulli.Liquido.Prandt

        if re <= 2300:
            Nu = h_anulli_Laminar(re, pr, a)
        elif re >= 1e4:
            Nu = h_anulli_Turbulent(re, pr, a)
        else:
            Nu = h_anulli_Transition(re, pr, a)

        return unidades.HeatTransfCoef(Nu*k/self.Di) 
Example #4
Source File: distillation.py    From pychemqt with GNU General Public License v3.0 6 votes vote down vote up
def volumen(self):
        self.Di = unidades.Length(0)
        self.L = unidades.Length(0)
        self.reborde = 0
        self.espesor = 0
        self.espesor_cabeza = 0

        V_carcasa = pi/4*self.Di**2*self.L

        if self.kwargs["cabeza"] == 0:
            V_cabeza = 4./3*pi/8*self.Di**3
        elif self.kwargs["cabeza"] == 1:
            V_cabeza = 4./3*pi/8/2*self.Di**3
        elif self.kwargs["cabeza"] == 2:
            V_cabeza = 0.215483/2*self.Di**3
        else:
            V_cabeza = 0.

        self.V = unidades.Volume(V_carcasa+V_cabeza) 
Example #5
Source File: tank.py    From pychemqt with GNU General Public License v3.0 6 votes vote down vote up
def volumen(self, cabeza):
        """
        cabeza: tipo de cabeza del recipiente
            0   -   Ellipsoidal
            1   -   Hemispherical
            2   -   Bumped
            3   -   Flat
        """
        V_carcasa=pi/4*self.Di**2*self.L

        if cabeza==0:
            V_cabeza=4./3*pi/8*self.Di**3
        elif cabeza==1:
            V_cabeza=4./3*pi/8/2*self.Di**3
        elif cabeza==2:
            V_cabeza=0.215483/2*self.Di**3
        else:
            V_cabeza=0.

        self.Volumen=Volume(V_carcasa+V_cabeza) 
Example #6
Source File: heatTransfer.py    From pychemqt with GNU General Public License v3.0 5 votes vote down vote up
def h_tube_Condensation_Shah(fluid, Di):
    """ref Pag 557 Kakac: Boiler..."""
    G = fluid.caudalmasico*4/pi/Di**2
    Re = Di*G/fluid.Liquido.mu
    Nul = 0.023*Re**0.8*fluid.Liquido.Prandt**0.4
    return Nul*((1-fluid.x)**0.8+3.8*fluid.x**0.76*(1-fluid.x)**0.04/fluid.Pr**0.38) 
Example #7
Source File: heatExchanger.py    From pychemqt with GNU General Public License v3.0 5 votes vote down vote up
def h_tubeside_laminar_condensation_Kern(self):
        return 0.815*(k**3*rho_l*(rho_l-rho_g)*g*l/(pi*mu_l*Do*(T-Tw)))**0.25 
Example #8
Source File: NH3.py    From pychemqt with GNU General Public License v3.0 5 votes vote down vote up
def _ThCondCritical(self, rho, T, fase):
        # Custom Critical enhancement

        # The paper use a diferent rhoc value to the EoS
        rhoc = 235

        t = abs(T-405.4)/405.4
        dPT = 1e5*(2.18-0.12/exp(17.8*t))
        nb = 1e-5*(2.6+1.6*t)

        DL = 1.2*Boltzmann*T**2/6/pi/nb/(1.34e-10/t**0.63*(1+t**0.5)) * \
            dPT**2 * 0.423e-8/t**1.24*(1+t**0.5/0.7)

        # Add correction for entire range of temperature, Eq 10
        DL *= exp(-36*t**2)

        X = 0.61*rhoc+16.5*log(t)
        if rho > 0.6*rhoc:
            # Eq 11
            DL *= X**2/(X**2+(rho-0.96*rhoc)**2)
        else:
            # Eq 14
            DL = X**2/(X**2+(0.6*rhoc-0.96*rhoc)**2)
            DL *= rho**2/(0.6*rhoc)**2

        return DL 
Example #9
Source File: heatTransfer.py    From pychemqt with GNU General Public License v3.0 5 votes vote down vote up
def plot(self, indice):
        self.diagrama.ax.clear()
        self.diagrama.ax.set_xlim(0, 6)
        self.diagrama.ax.set_ylim(0, 1)
        title = QtWidgets.QApplication.translate(
            "pychemqt", "Heat Transfer effectiveness")
        self.diagrama.ax.set_title(title, size='12')
        self.diagrama.ax.set_xlabel("NTU", size='12')
        self.diagrama.ax.set_ylabel("ε", size='14')

        flujo = self.flujo[indice][1]
        self.mixed.setVisible(flujo == "CrFSMix")
        kw = {}
        if flujo == "CrFSMix":
            kw["mixed"] = str(self.mixed.currentText())

        C = [0, 0.2, 0.4, 0.6, 0.8, 1.]

        NTU = arange(0, 6.1, 0.1)
        for ci in C:
            e = [0]
            for N in NTU[1:]:
                e.append(efectividad(N, ci, flujo, **kw))
            self.diagrama.plot(NTU, e, "k")

            fraccionx = (NTU[40]-NTU[30])/6
            fracciony = (e[40]-e[30])
            try:
                angle = arctan(fracciony/fraccionx)*360/2/pi
            except ZeroDivisionError:
                angle = 90

            self.diagrama.ax.annotate(
                "C*=%0.1f" % ci, (NTU[29], e[30]), rotation=angle,
                size="medium", ha="left", va="bottom")

        self.diagrama.draw()

        img = image.imread('images/equation/%s.png' % flujo)
        self.image.set_data(img)
        self.refixImage() 
Example #10
Source File: inception_v4_io.py    From DBNet with Apache License 2.0 5 votes vote down vote up
def summary_scalar(pred, label):
    threholds = [5, 4, 3, 2, 1, 0.5]
    angles = [float(t) / 180 * scipy.pi for t in threholds]
    speeds = [float(t) / 20 for t in threholds]

    for i in range(len(threholds)):
        scalar_angle = "angle(" + str(angles[i]) + ")"
        scalar_speed = "speed(" + str(speeds[i]) + ")"
        ac_angle = tf.abs(tf.subtract(pred[:, 1], label[:, 1])) < threholds[i]
        ac_speed = tf.abs(tf.subtract(pred[:, 0], label[:, 0])) < threholds[i]
        ac_angle = tf.reduce_mean(tf.cast(ac_angle, tf.float32))
        ac_speed = tf.reduce_mean(tf.cast(ac_speed, tf.float32))

        tf.summary.scalar(scalar_angle, ac_angle)
        tf.summary.scalar(scalar_speed, ac_speed) 
Example #11
Source File: heatTransfer.py    From pychemqt with GNU General Public License v3.0 5 votes vote down vote up
def plot(self, indice):
        self.diagrama.ax.clear()
        self.diagrama.ax.set_xlim(0, 1)
        self.diagrama.ax.set_ylim(0, 1)
        self.diagrama.ax.set_title(QtWidgets.QApplication.translate("pychemqt", "$\Delta T_{ml}$ Correction Factor", None), size='12')
        self.diagrama.ax.set_xlabel("$P=\\frac{T_{1o}-T_{1i}}{T_{2i}-T_{1i}}$", size='12')
        self.diagrama.ax.set_ylabel("F", size='14')

        flujo = self.flujo[indice][1]
#        self.mixed.setVisible(flujo=="CrFSMix")
        kwargs = {}
        if flujo == "CrFSMix":
            kwargs["mixed"] = str(self.mixed.currentText())

        R = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1., 1.2, 1.4, 1.6,
             1.8, 2, 2.5, 3, 4, 6, 8, 10, 15, 20]
#        R=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]

        P = arange(0, 1.01, 0.01)
        for ri in R:
            f = [CorrectionFactor(p, ri, flujo, **kwargs) for p in P]
            self.diagrama.plot(P, f, "k")

#            fraccionx=P[90]-P[80]
#            fracciony=f[90]-f[80]
#            try:
#                angle=arctan(fracciony/fraccionx)*360/2/pi
#            except ZeroDivisionError:
#                angle=90
#            self.diagrama.ax.annotate("R=%0.1f" %ri, (P[90], f[90]), rotation=angle, size="medium", horizontalalignment="left", verticalalignment="bottom")

        self.diagrama.draw()

        img = image.imread('images/equation/%s.png' % flujo)
        self.image.set_data(img)
        self.refixImage() 
Example #12
Source File: heatTransfer.py    From pychemqt with GNU General Public License v3.0 5 votes vote down vote up
def plot(self, indice):
        self.diagrama.ax.clear()
        self.diagrama.ax.set_xlim(0, 1)
        self.diagrama.ax.set_ylim(0, 1)
        self.diagrama.ax.set_title(QtWidgets.QApplication.translate("pychemqt", "$\Delta T_{ml}$ Correction Factor", None), size='12')
        self.diagrama.ax.set_xlabel("$P=\\frac{T_{1o}-T_{1i}}{T_{2i}-T_{1i}}$", size='12')
        self.diagrama.ax.set_ylabel("F", size='14')

        flujo = self.flujo[indice][1]
#        self.mixed.setVisible(flujo=="CrFSMix")
        kwargs = {}
        if flujo == "CrFSMix":
            kwargs["mixed"] = str(self.mixed.currentText())

        R = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1., 1.2, 1.4,
             1.6, 1.8, 2, 2.5, 3, 4, 6, 8, 10]

        P = arange(0, 1.01, 0.01)
        for ri in R:
            f = [Fi(p, ri, flujo, **kwargs) for p in P]
            self.diagrama.plot(P, f, "k")

        NTU = [0.2, 0.4, 0.6, 0.8, 1., 1.2, 1.4, 1.6, 1.8, 2.0, 2.5, 3.]
        for ntu in NTU:
            self.diagrama.plot([0, 1], [0, 1./ntu], "k", linestyle=":")
#            fraccionx=P[90]-P[80]
#            fracciony=f[90]-f[80]
#            try:
#                angle=arctan(fracciony/fraccionx)*360/2/pi
#            except ZeroDivisionError:
#                angle=90
#            self.diagrama.ax.annotate("R=%0.1f" %ri, (P[90], f[90]), rotation=angle, size="medium", horizontalalignment="left", verticalalignment="bottom")

        self.diagrama.draw()

        img = image.imread('images/equation/%s.png' % flujo)
        self.image.set_data(img)
        self.refixImage() 
Example #13
Source File: densenet169_pm.py    From DBNet with Apache License 2.0 5 votes vote down vote up
def summary_scalar(pred, label):
    threholds = [5, 4, 3, 2, 1, 0.5]
    angles = [float(t) / 180 * scipy.pi for t in threholds]
    speeds = [float(t) / 20 for t in threholds]

    for i in range(len(threholds)):
        scalar_angle = "angle(" + str(angles[i]) + ")"
        scalar_speed = "speed(" + str(speeds[i]) + ")"
        ac_angle = tf.abs(tf.subtract(pred[:, 1], label[:, 1])) < threholds[i]
        ac_speed = tf.abs(tf.subtract(pred[:, 0], label[:, 0])) < threholds[i]
        ac_angle = tf.reduce_mean(tf.cast(ac_angle, tf.float32))
        ac_speed = tf.reduce_mean(tf.cast(ac_speed, tf.float32))

        tf.summary.scalar(scalar_angle, ac_angle)
        tf.summary.scalar(scalar_speed, ac_speed) 
Example #14
Source File: nvidia_pm.py    From DBNet with Apache License 2.0 5 votes vote down vote up
def summary_scalar(pred, label):
    threholds = [5, 4, 3, 2, 1, 0.5]
    angles = [float(t) / 180 * scipy.pi for t in threholds]
    speeds = [float(t) / 20 for t in threholds]

    for i in range(len(threholds)):
        scalar_angle = "angle(" + str(angles[i]) + ")"
        scalar_speed = "speed(" + str(speeds[i]) + ")"
        ac_angle = tf.abs(tf.subtract(pred[:, 1], label[:, 1])) < threholds[i]
        ac_speed = tf.abs(tf.subtract(pred[:, 0], label[:, 0])) < threholds[i]
        ac_angle = tf.reduce_mean(tf.cast(ac_angle, tf.float32))
        ac_speed = tf.reduce_mean(tf.cast(ac_speed, tf.float32))

        tf.summary.scalar(scalar_angle, ac_angle)
        tf.summary.scalar(scalar_speed, ac_speed) 
Example #15
Source File: nvidia_io.py    From DBNet with Apache License 2.0 5 votes vote down vote up
def summary_scalar(pred, label):
    threholds = [5, 4, 3, 2, 1, 0.5]
    angles = [float(t) / 180 * scipy.pi for t in threholds]
    speeds = [float(t) / 20 for t in threholds]

    for i in range(len(threholds)):
        scalar_angle = "angle(" + str(angles[i]) + ")"
        scalar_speed = "speed(" + str(speeds[i]) + ")"
        ac_angle = tf.abs(tf.subtract(pred[:, 1], label[:, 1])) < threholds[i]
        ac_speed = tf.abs(tf.subtract(pred[:, 0], label[:, 0])) < threholds[i]
        ac_angle = tf.reduce_mean(tf.cast(ac_angle, tf.float32))
        ac_speed = tf.reduce_mean(tf.cast(ac_speed, tf.float32))

        tf.summary.scalar(scalar_angle, ac_angle)
        tf.summary.scalar(scalar_speed, ac_speed) 
Example #16
Source File: healmap.py    From astrolibpy with GNU General Public License v3.0 5 votes vote down vote up
def _ang2vert_eq(nside,theta,phi,z):
		a= 4./3./nside
		b= 8./3./sc.pi
		deltaZ= a
		deltaPhi= a/b
		out= []
		out.append([sc.arccos(z+deltaZ/2),phi])
		out.append([theta,phi-deltaPhi/2.])
		out.append([sc.arccos(z-deltaZ/2),phi])
		out.append([theta,phi+deltaPhi/2.])
		return sc.array(out) 
Example #17
Source File: healmap.py    From astrolibpy with GNU General Public License v3.0 5 votes vote down vote up
def _ang2vert(nside,theta,phi,z):
		(xsCenter,ysCenter)= bovy_healpy._ang2xsys(z,phi)
		delta= sc.pi/4./nside
		out= []
		out.append(bovy_healpy._xsys2ang(xsCenter,ysCenter+delta))
		out.append(bovy_healpy._xsys2ang(xsCenter-delta,ysCenter))
		out.append(bovy_healpy._xsys2ang(xsCenter,ysCenter-delta))
		out.append(bovy_healpy._xsys2ang(xsCenter+delta,ysCenter))
		return sc.array(out) 
Example #18
Source File: healmap.py    From astrolibpy with GNU General Public License v3.0 5 votes vote down vote up
def _xsys2ang(xs,ys):
		if sc.fabs(ys) <= sc.pi/4.:
			return [sc.arccos(8./3./sc.pi*ys),xs]
		else:
			xt= (xs % (sc.pi/2.))
			fabsys= sc.fabs(ys)
			theta= sc.arccos((1.-1./3.*(2.-4.*fabsys/sc.pi)**2.)*ys/fabsys)
			if fabsys == sc.pi/2.:
				phi= xs-fabsys+sc.pi/4.
			else:
				phi= xs-(fabsys-sc.pi/4.)/(fabsys-sc.pi/2.)*(xt-sc.pi/4.) 
			return [theta % (sc.pi+0.0000000001),phi % (2.*sc.pi)] #Hack 
Example #19
Source File: healmap.py    From astrolibpy with GNU General Public License v3.0 5 votes vote down vote up
def _ang2xsys(z,phi):
		if sc.fabs(z) <= 2./3.:
			return [phi,3.*sc.pi/8.*z]
		else:
			phit= (phi % (sc.pi/2.))
			sigz= bovy_healpy._sigma(z)
			return [phi-(sc.fabs(sigz)-1.)*(phit-sc.pi/4.),sc.pi/4.*sigz] 
Example #20
Source File: train_demo.py    From DBNet with Apache License 2.0 5 votes vote down vote up
def train_one_epoch(sess, ops, train_writer, data_input):
    """ ops: dict mapping from string to tf ops """
    is_training = True
    num_batches = data_input.num_train // BATCH_SIZE
    loss_sum = 0
    acc_a_sum = 0
    acc_s_sum = 0

    for batch_idx in range(num_batches):
        if "io" in MODEL_FILE:
            imgs, labels = data_input.load_one_batch(BATCH_SIZE, "train")
            feed_dict = {ops['imgs_pl']: imgs,
                         ops['labels_pl']: labels,
                         ops['is_training_pl']: is_training}
        else:
            imgs, others, labels = data_input.load_one_batch(BATCH_SIZE, "train")
            feed_dict = {ops['imgs_pl'][0]: imgs,
                         ops['imgs_pl'][1]: others,
                         ops['labels_pl']: labels,
                         ops['is_training_pl']: is_training}

        summary, step, _, loss_val, pred_val = sess.run([ops['merged'],
                                                         ops['step'],
                                                         ops['train_op'],
                                                         ops['loss'],
                                                         ops['pred']],
                                                        feed_dict=feed_dict)
        train_writer.add_summary(summary, step)
        loss_sum += np.mean(np.square(np.subtract(pred_val, labels)))
        acc_a = np.abs(np.subtract(pred_val[:, 1], labels[:, 1])) < (5.0 / 180 * scipy.pi)
        acc_a = np.mean(acc_a)
        acc_a_sum += acc_a
        acc_s = np.abs(np.subtract(pred_val[:, 0], labels[:, 0])) < (5.0 / 20)
        acc_s = np.mean(acc_s)
        acc_s_sum += acc_s

    log_string('mean loss: %f' % (loss_sum / float(num_batches)))
    log_string('accuracy (angle): %f' % (acc_a_sum / float(num_batches)))
    log_string('accuracy (speed): %f' % (acc_s_sum / float(num_batches))) 
Example #21
Source File: train_demo.py    From DBNet with Apache License 2.0 5 votes vote down vote up
def eval_one_epoch(sess, ops, test_writer, data_input):
    """ ops: dict mapping from string to tf ops """
    is_training = False
    loss_sum = 0

    num_batches = data_input.num_val // BATCH_SIZE
    loss_sum = 0
    acc_a_sum = 0
    acc_s_sum = 0

    for batch_idx in range(num_batches):
        if "io" in MODEL_FILE:
            imgs, labels = data_input.load_one_batch(BATCH_SIZE, "val")
            feed_dict = {ops['imgs_pl']: imgs,
                         ops['labels_pl']: labels,
                         ops['is_training_pl']: is_training}
        else:
            imgs, others, labels = data_input.load_one_batch(BATCH_SIZE, "val")
            feed_dict = {ops['imgs_pl'][0]: imgs,
                         ops['imgs_pl'][1]: others,
                         ops['labels_pl']: labels,
                         ops['is_training_pl']: is_training}
        summary, step, _, loss_val, pred_val = sess.run([ops['merged'],
                                                         ops['step'],
                                                         ops['train_op'],
                                                         ops['loss'],
                                                         ops['pred']],
                                                        feed_dict=feed_dict)
        test_writer.add_summary(summary, step)
        loss_sum += np.mean(np.square(np.subtract(pred_val, labels)))
        acc_a = np.abs(np.subtract(pred_val[:, 1], labels[:, 1])) < (5.0 / 180 * scipy.pi)
        acc_a = np.mean(acc_a)
        acc_a_sum += acc_a
        acc_s = np.abs(np.subtract(pred_val[:, 0], labels[:, 0])) < (5.0 / 20)
        acc_s = np.mean(acc_s)
        acc_s_sum += acc_s

    log_string('eval mean loss: %f' % (loss_sum / float(num_batches)))
    log_string('eval accuracy (angle): %f' % (acc_a_sum / float(num_batches)))
    log_string('eval accuracy (speed): %f' % (acc_s_sum / float(num_batches))) 
Example #22
Source File: heatTransfer.py    From pychemqt with GNU General Public License v3.0 5 votes vote down vote up
def h_tube_Condensation_Cavallini(fluid, Di):
    """ref Pag 557 Kakac: Boiler..."""
    Ge = fluid.caudalmasico*4/pi/Di**2*((1-fluid.x)+fluid.x*(fluid.Liquido.rho/fluid.Vapor.rho)**0.5)
    Re = Di*Ge/fluid.Liquido.mu
    return 0.05*Re**0.8*fluid.Liquido.Prandt**(1./3) 
Example #23
Source File: predict.py    From DBNet with Apache License 2.0 5 votes vote down vote up
def pred_one_epoch(sess, ops, data_input):
    """ ops: dict mapping from string to tf ops """
    is_training = False
    preds = []
    num_batches = data_input.num_test // BATCH_SIZE

    for batch_idx in range(num_batches):
        if "io" in MODEL_FILE:
            imgs = data_input.load_one_batch(BATCH_SIZE, "test")
            feed_dict = {ops['imgs_pl']: imgs,
                         ops['is_training_pl']: is_training}
        else:
            imgs, others = data_input.load_one_batch(BATCH_SIZE, "test")
            feed_dict = {ops['imgs_pl'][0]: imgs,
                         ops['imgs_pl'][1]: others,
                         ops['is_training_pl']: is_training}

        pred_val = sess.run(ops['pred'], feed_dict=feed_dict)
        preds.append(pred_val)

    preds = np.vstack(preds)
    print (preds.shape)
    # preds[:, 1] = preds[:, 1] * 180.0 / scipy.pi
    # preds[:, 0] = preds[:, 0] * 20 + 20

    np.savetxt(os.path.join(RESULT_DIR, "behavior_pred.txt"), preds)

    output_dir = os.path.join(RESULT_DIR, "results")
    if not os.path.exists(output_dir):
        os.makedirs(output_dir)
    i_list = get_dicts(description="test")
    counter = 0
    for i, num in enumerate(i_list):
        np.savetxt(os.path.join(output_dir, str(i) + ".txt"), preds[counter:counter+num,:])
        counter += num
    # plot_acc(preds, labels) 
Example #24
Source File: evaluate.py    From DBNet with Apache License 2.0 5 votes vote down vote up
def plot_acc(preds, labels, counts = 100):
    a_list = []
    s_list = []
    for i in range(counts):
        acc_a = np.abs(np.subtract(preds[:, 1], labels[:, 1])) < (20.0 / 180 * scipy.pi / counts * i)
        a_list.append(np.mean(acc_a))

    for i in range(counts):
        acc_s = np.abs(np.subtract(preds[:, 0], labels[:, 0])) < (15.0 / 20 / counts * i)
        s_list.append(np.mean(acc_s))

    print (len(a_list), len(s_list))
    a_xaxis = [20.0 / counts * i for i in range(counts)]
    s_xaxis = [15.0 / counts * i for i in range(counts)]

    auc_angle = np.trapz(np.array(a_list), x=a_xaxis) / 20.0
    auc_speed = np.trapz(np.array(s_list), x=s_xaxis) / 15.0

    plt.style.use('ggplot')
    plt.figure()
    plt.plot(a_xaxis, np.array(a_list), label='Area Under Curve (AUC): %f' % auc_angle)
    plt.legend(loc='best')
    plt.xlabel("Threshold (angle)")
    plt.ylabel("Validation accuracy")
    plt.savefig(os.path.join(RESULT_DIR, "acc_angle.png"))
    plt.figure()
    plt.plot(s_xaxis, np.array(s_list), label='Area Under Curve (AUC): %f' % auc_speed)
    plt.xlabel("Threshold (speed)")
    plt.ylabel("Validation accuracy")
    plt.legend(loc='best')
    plt.savefig(os.path.join(RESULT_DIR, 'acc_spped.png')) 
Example #25
Source File: nvidia_pn.py    From DBNet with Apache License 2.0 5 votes vote down vote up
def summary_scalar(pred, label):
    threholds = [5, 4, 3, 2, 1, 0.5]
    angles = [float(t) / 180 * scipy.pi for t in threholds]
    speeds = [float(t) / 20 for t in threholds]

    for i in range(len(threholds)):
        scalar_angle = "angle(" + str(angles[i]) + ")"
        scalar_speed = "speed(" + str(speeds[i]) + ")"
        ac_angle = tf.abs(tf.subtract(pred[:, 1], label[:, 1])) < threholds[i]
        ac_speed = tf.abs(tf.subtract(pred[:, 0], label[:, 0])) < threholds[i]
        ac_angle = tf.reduce_mean(tf.cast(ac_angle, tf.float32))
        ac_speed = tf.reduce_mean(tf.cast(ac_speed, tf.float32))

        tf.summary.scalar(scalar_angle, ac_angle)
        tf.summary.scalar(scalar_speed, ac_speed) 
Example #26
Source File: resnet152_io.py    From DBNet with Apache License 2.0 5 votes vote down vote up
def summary_scalar(pred, label):
    threholds = [5, 4, 3, 2, 1, 0.5]
    angles = [float(t) / 180 * scipy.pi for t in threholds]
    speeds = [float(t) / 20 for t in threholds]

    for i in range(len(threholds)):
        scalar_angle = "angle(" + str(angles[i]) + ")"
        scalar_speed = "speed(" + str(speeds[i]) + ")"
        ac_angle = tf.abs(tf.subtract(pred[:, 1], label[:, 1])) < threholds[i]
        ac_speed = tf.abs(tf.subtract(pred[:, 0], label[:, 0])) < threholds[i]
        ac_angle = tf.reduce_mean(tf.cast(ac_angle, tf.float32))
        ac_speed = tf.reduce_mean(tf.cast(ac_speed, tf.float32))

        tf.summary.scalar(scalar_angle, ac_angle)
        tf.summary.scalar(scalar_speed, ac_speed) 
Example #27
Source File: sound_waves.py    From qmpy with MIT License 5 votes vote down vote up
def main(argv):
    C = read_file.read_file(argv[0])
    C.pop(0)
    C = sp.array(C,float)
    density,natoms,molmass = read_file.read_file(argv[1])[0]
    density = float(density)  # kg/m**3
    natoms = int(natoms)
    molmass = float(molmass)  # kg/mol
    integral = spherical_integral(C,density)  # (s/m)**3
    mean_vel = (integral/12./sp.pi)**(-1/3.)
    debeye_temp = PLANCKCONST/BOLTZCONST*(3.*natoms*AVONUM*
                      density/4./sp.pi/molmass)**(1/3.)*mean_vel
    print debeye_temp,mean_vel 
Example #28
Source File: resnet152_pm.py    From DBNet with Apache License 2.0 5 votes vote down vote up
def summary_scalar(pred, label):
    threholds = [5, 4, 3, 2, 1, 0.5]
    angles = [float(t) / 180 * scipy.pi for t in threholds]
    speeds = [float(t) / 20 for t in threholds]

    for i in range(len(threholds)):
        scalar_angle = "angle(" + str(angles[i]) + ")"
        scalar_speed = "speed(" + str(speeds[i]) + ")"
        ac_angle = tf.abs(tf.subtract(pred[:, 1], label[:, 1])) < threholds[i]
        ac_speed = tf.abs(tf.subtract(pred[:, 0], label[:, 0])) < threholds[i]
        ac_angle = tf.reduce_mean(tf.cast(ac_angle, tf.float32))
        ac_speed = tf.reduce_mean(tf.cast(ac_speed, tf.float32))

        tf.summary.scalar(scalar_angle, ac_angle)
        tf.summary.scalar(scalar_speed, ac_speed) 
Example #29
Source File: inception_v4_pm.py    From DBNet with Apache License 2.0 5 votes vote down vote up
def summary_scalar(pred, label):
    threholds = [5, 4, 3, 2, 1, 0.5]
    angles = [float(t) / 180 * scipy.pi for t in threholds]
    speeds = [float(t) / 20 for t in threholds]

    for i in range(len(threholds)):
        scalar_angle = "angle(" + str(angles[i]) + ")"
        scalar_speed = "speed(" + str(speeds[i]) + ")"
        ac_angle = tf.abs(tf.subtract(pred[:, 1], label[:, 1])) < threholds[i]
        ac_speed = tf.abs(tf.subtract(pred[:, 0], label[:, 0])) < threholds[i]
        ac_angle = tf.reduce_mean(tf.cast(ac_angle, tf.float32))
        ac_speed = tf.reduce_mean(tf.cast(ac_speed, tf.float32))

        tf.summary.scalar(scalar_angle, ac_angle)
        tf.summary.scalar(scalar_speed, ac_speed) 
Example #30
Source File: densenet169_pn.py    From DBNet with Apache License 2.0 5 votes vote down vote up
def summary_scalar(pred, label):
    threholds = [5, 4, 3, 2, 1, 0.5]
    angles = [float(t) / 180 * scipy.pi for t in threholds]
    speeds = [float(t) / 20 for t in threholds]

    for i in range(len(threholds)):
        scalar_angle = "angle(" + str(angles[i]) + ")"
        scalar_speed = "speed(" + str(speeds[i]) + ")"
        ac_angle = tf.abs(tf.subtract(pred[:, 1], label[:, 1])) < threholds[i]
        ac_speed = tf.abs(tf.subtract(pred[:, 0], label[:, 0])) < threholds[i]
        ac_angle = tf.reduce_mean(tf.cast(ac_angle, tf.float32))
        ac_speed = tf.reduce_mean(tf.cast(ac_speed, tf.float32))

        tf.summary.scalar(scalar_angle, ac_angle)
        tf.summary.scalar(scalar_speed, ac_speed)