Ejemplo n.º 1
0
	def Run(self):
		if self.started_flag != True:
			self.thread_source = Data_Source(self,self.url,self.cmd_queue,self.data_queue)
			self.thread_source.setDaemon(True)
			self.thread_source.start() #启动后台线程, 与endpoint server进行连接与通信
			self.started_flag = True
			serial_name = self.url.split("/")[1]
			open_cmd = "open:%s:%s"%(serial_name,'115200')
			print open_cmd
			self.cmd_queue.put(open_cmd)
			time.sleep(0.01)
			#set hard ware below
			self.SetupHW()

		 # flush outdated data
		while not self.data_queue.empty():
			self.data_queue.get()
		self.cmd_queue.put("run:")
Ejemplo n.º 2
0
from autoencoder import Autoencoder
from config import Config
from data_source import Data_Source

config = Config()
config.init()
model = Autoencoder(config)
data_source = Data_Source(config)
model.train(data_source)
Ejemplo n.º 3
0
from config import Config
from data_source import Data_Source
import numpy as np
import tensorflow as tf

config = Config()
config.init()
model = Autoencoder(config)
if config.data_source == "mnist":
    from data_source import Data_Source
elif config.data_source == "ucf":
    from data_source_ucf import Data_Source
elif config.data_source == "youtube":
    from data_source_youtube import Data_Source

data_source = Data_Source(config)
if config.train:
    model.train(data_source)
else:
    assert config.load_model != ""
    model.saver.restore(model.sess, config.load_model)

    sample, target = data_source.get_train_batch_ae()
    logit, decode = model.sess.run([model.logits, model.decode],
                                   feed_dict={model.sample_input: sample})

    print("=== cross_entropy ===")

    ce = model.sess.run(
        tf.reduce_mean(
            tf.reduce_sum(tf.nn.sigmoid_cross_entropy_with_logits(
Ejemplo n.º 4
0
class Signal(wx.Dialog):
	def __init__(self,window=None,ok_colour="green",bad_colour="red",url=None,table=None):
		super(Signal, self).__init__(parent=None)
		self.window = window
		self.ok_colour = ok_colour
		self.old_ok_colour = ok_colour
		self.bad_colour= bad_colour
		self.old_bad_colour = bad_colour
		self.data = []
		self.cmd_queue=Queue(-10)
		self.data_queue=Queue(-10)
		self.started_flag = False
		self.thread_source = None
		self.count = 0
		self.xmax= 0.0
		self.ymax= 0.0
		self.SetRefer_entries(table)
		self.SetUrl(url)
		self.Bind(EVT_MY_EVENT, self.OnNewData)
		self.trig_status = False
		self.record = Test_Record()
		#self.NewRecordSN = ''
		self.status = None
		self.eut = None
		self.thermo = Thermo()
		self.filter_option = True

	def SetPN(self,eut):#extract PN from eut object
		if not isinstance(eut,Eut):
			print "Error: invalid type, should be Eut!"
			return None
		self.eut = eut
		self.record.SetPN(eut.GetPN())
		self.window.UpdateRecord()

	def SetSN(self,SN):
		self.record.SetSN(SN)
		self.window.UpdateRecord()

	def UploadSN(self,SN):
		self.window.UploadSN(SN)

	def SetWindow(self,window):
		self.window = window

	def GetData(self):
		return self.data

	def SetOkColour(self,colour):
		self.ok_colour = colour

	def GetOkColour(self):
		return self.ok_colour

	def GetBackColour(self):
		return self.window.GetBackColour()

	def GetGridColour(self):
		return self.window.GetGridColour()

	def GetFilterOption(self):
		return self.filter_option
		
	def SetFilterOption(self,option):
		self.filter_option = option
		if option == True:
			self.cmd_queue.put("Filter:On")
		else:
			self.cmd_queue.put("Filter:Off")

	def SetBadColour(self,colour):
		self.bad_colour = colour 

	def GetBadColour(self):
		return self.bad_colour

	def SetUrl(self,url):
		if not url:
			return
		self.url = url

	def GetUrl(self):
		return self.url

	def SetRefer_entries(self,table):
		if table and isinstance(table,list):
			self.refer_entries = table
			self.refer_entries.sort(key=lambda x:x.GetYvalue())
			#print "signal max value",self.refer_entries[-1].GetYvalue()
			x0 = self.refer_entries[ 0].GetXvalue()
			xn = self.refer_entries[-1].GetXvalue()
			if x0 > xn:
				xmax = x0
			else:
				xmax = xn

			ymin = self.refer_entries[ 0].GetYvalue()
			ymax = self.refer_entries[-1].GetYvalue()
			self.SetMaxValue(xmax,ymax)
			#gPGA.find_solution(range_=(ymin,ymax),unit="Ohm")
			for x in self.refer_entries:
				print "signal refers value X,Y",x.GetXvalue(),x.GetYvalue()
		else:
			self.refer_entries = None


	def SetMaxValue(self,xmax,ymax):
		self.xmax= float(xmax)
		self.ymax= float(ymax)

	def GetMaxY(self):
		return self.ymax

	def GetMaxX(self):
		return self.xmax

	def SetupHW(self):
		cmd_map     =   {'Ohm':'R','ohm':'R',
				'Vol':'U','vol':'U',
				'Amp':'I','amp':'I',
				}

		#根据单位设置RUI
		unit = self.eut.GetYunit()
		sw_cmd = "adc:swt:%s:"%(cmd_map[unit[:3]])
		print sw_cmd
		self.cmd_queue.put(sw_cmd)
		time.sleep(0.01)

		#根据range_设置PGA
		range_ = self.eut.GetRange()
		r_code,a_code =  gPGA.find_solution(range_,unit)
		pga_cmd = "adc:pga:r:%d:a:%d"%(r_code,a_code)
		print pga_cmd
		self.cmd_queue.put(pga_cmd)
		time.sleep(0.01)

		


	def Run(self):
		if self.started_flag != True:
			self.thread_source = Data_Source(self,self.url,self.cmd_queue,self.data_queue)
			self.thread_source.setDaemon(True)
			self.thread_source.start() #启动后台线程, 与endpoint server进行连接与通信
			self.started_flag = True
			serial_name = self.url.split("/")[1]
			open_cmd = "open:%s:%s"%(serial_name,'115200')
			print open_cmd
			self.cmd_queue.put(open_cmd)
			time.sleep(0.01)
			#set hard ware below
			self.SetupHW()

		 # flush outdated data
		while not self.data_queue.empty():
			self.data_queue.get()
		self.cmd_queue.put("run:")

	def Init_Data(self):
		self.data = []
		self.window.SetUnknown()
		self.window.Refresh(True)

	def OnQueryDB(self,event):
		QueryUI = Server_("python refer_table.py")
		QueryUI.start()

	def Pause(self):
		print "signal pause.....\n"
		self.cmd_queue.put("stop:")
		while not self.data_queue.empty(): # flush outdated data
			self.data_queue.get()
		#self.Init_Data()

	def Configure(self,command):
		self.cmd_queue.put(command)
	
	def SampleThermo(self):
		if not self.eut.HasNTC():
			return
		thermo_cmd = "adc:temp:\r"
		print thermo_cmd
		self.cmd_queue.put(thermo_cmd)


	def OnNewData(self, event):
		if not self.refer_entries:
			return
		out = ''
		pos = 0
		value = 0
		while not self.data_queue.empty():
			item = self.data_queue.get()
			if isinstance(item,dict):
				if self.trig_status == False:
					continue
				Xvalue,Yvalue_ = item["value"]
				Yvalue = gPGA.find_result4R(Yvalue_)
				#print "Yvalue of R:",Yvalue
				length = item["length"]
				if length > 100 or item['flag'] == 'step':
					length = 100

				refer_entry  = self.GetReferEntry(Xvalue,Yvalue)
				if not refer_entry:
					return
				#print "new data .............",Xvalue,Yvalue,length
				#print "searched refer_entry X,Y:",refer_entry.GetXvalue(),refer_entry.GetYvalue()
				Xprecision,Yprecision,xstatus,ystatus = refer_entry.Validate(Xvalue,Yvalue)
				if xstatus==True and ystatus==True:
					status = True
				else:
					status = False
					self.status = False
					self.window.SetFail()
				record= Refer_Entry(
						Xvalue=Xvalue,
						Yvalue=Yvalue,
						Xprecision=Xprecision,
						Yprecision=Yprecision,
						valid_status=status)
				record.SetLength(length)
				self.data.append(record)
				self.record.AppendRecord(
					Record_Entry(
						refer	= refer_entry,
						record	= record
						)
					)
				self.window.window.UpdateRecordOnce() # signal_control.UpdateRecord()
				#self.window.DrawData()
			else:
				if item.startswith("trigger"):
					print "'signal' triggering.........."
					self.trig_status = True
					self.Init_Data()
					self.record.InitRecord()
					self.window.UpdateRecord()
					self.window.SetUnknown()
					NewRecordSN = self.record.AdjustSN(1)
					self.UploadSN(NewRecordSN) 
					#收到触发信号,可以采集温度信号了!
					self.SampleThermo()
				elif item.startswith("sleep"):
					print "'signal' sleeping.........."
					if  self.trig_status == True:
						self.trig_status = False
						if self.status != False:
							self.window.SetPass()
						print "saving.........."
						self.record.Save2DBZ()
						print "saving ok.........."
				elif item.startswith("0t:"):
					hex_NTC = int(item[3:7],16)
					hex_PT  = int(item[7:11],16)
					(result,temprature,Rntc,Rref)=self.record.SetupThermo(hex_NTC,hex_PT)
					self.window.window.SetThermo(str(round(temprature,3)))
					self.window.window.SetThermoValue(str(round(Rntc,3)))
					self.window.window.SetThermoRefer(str(round(Rref,3)))
			self.window.Refresh(True)


	def GetRefer_X(self,Xvalue=0,Yvalue=0):
		refer_entry =None

		#print len(self.refer_entries),self.refer_entries
		x0 = self.refer_entries[0].GetXvalue()
		xn = self.refer_entries[-1].GetXvalue()
		if x0 > xn:
			Xmax =self.refer_entries[0]
			Xmin =self.refer_entries[-1]
		else:
			Xmax =self.refer_entries[-1]
			Xmin =self.refer_entries[0]
		#print "Xmin,Xmax,X--------------------",Xmin.GetXvalue(),Xmax.GetXvalue(),Xvalue
		if Xvalue >=   Xmax.GetXvalue():
			refer_entry = Xmax
		elif Xvalue <= Xmin.GetXvalue():
			refer_entry = Xmin
		else:
			p0 = self.refer_entries[0]
			for p1 in self.refer_entries:
				x0_ = p0.GetXvalue()
				x1  = p1.GetXvalue()
				delta0 = abs(Xvalue - x0_)
				delta1 = abs(Xvalue - x1)
				#judge being within by comparing delta_sum 
				if (delta0 + delta1) > abs(x1 - x0_):
					p0 = p1
					continue
				#use nearby Yvalue
				y0 = p0.GetYvalue()
				y1 = p1.GetYvalue()
				delta0 = Yvalue - y0
				delta1 = Yvalue - y1
				if abs(delta0) < abs(delta1): 
					refer_entry =  p0
				else:
					refer_entry =  p1
				break
		return refer_entry

	def GetRefer_Y(self,Xvalue=0,Yvalue=0):
		refer_entry= None
		if Yvalue <= self.refer_entries[0].GetYvalue():#outof range
				refer_entry =  self.refer_entries[0]
		elif Yvalue >= self.refer_entries[-1].GetYvalue():#outof range
				refer_entry =  self.refer_entries[-1]
		else:
			p0 = self.refer_entries[0]
			for p1 in self.refer_entries:
				y0 = p0.GetYvalue()
				y1 = p1.GetYvalue()
				delta0 = abs(Yvalue - y0)
				delta1 = abs(Yvalue - y1)
				#judge being within by comparing delta_sum 
				if (delta0 + delta1) > abs(y1 - y0):
					p0 = p1
					continue
				#use nearby Yvalue
				if abs(delta0) < abs(delta1): 
					refer_entry =  p0
				else:
					refer_entry =  p1
				break

		return refer_entry # if not found, return None object

	def GetReferEntry(self,Xvalue=0,Yvalue=0):
		'''Xvalue should be None for using Yvalue as index,
		or integer for using itself as index '''
		refer_entry =None
		refer_entry = self.GetRefer_Y(Xvalue,Yvalue)
		return refer_entry # if not found, return None object