read函数的返回值的问题

文件大小size_file明显是:17864字节。 为何第一次read返回值是48? 第二次read返回值是0?

代码:
图片说明

从属性看文件的大小:
图片说明

2个回答

read后,已经读进8ehdr,并且到最后了,已经读不到了

read(fd,&ehdr, 52)-----我只要求最多读52个而已,为什么会读到了最后呢?

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
关于python函数递归返回值的问题
这是一个匹配字典中词语的函数。 按理说已经匹配成功了 在return之前加个print 输出结果是对的 但是在外面调用输出来就是None 不知道为什么 求大神!! ``` def find_word(dictionary,word): if word in dictionary: return word else: if len(word)-1 == 0: return word else: word = word[0:len(word)-1] find_word(dictionary,word) dictionary = read_dic() print(find_word(dictionary,"热烈欢迎新")) ```
串口通信,如果read函数返回值是-1,可能是因为?
1、用open函数打开串口时候返回值不是-1.可见正常打开了 2、让ARM(上位)与8051(下位)通信,协议是9600,8N1(经常搞通信的都懂的) 3、51单片机大概每秒就向ARM发送一个byte,8位。 4、结果qtopia的terminal上一直打印“Read Error” 5、关掉terminal,打开qtipia自带的串口助手,竟然也接收不到信号! 6、把8051电源关掉,让通信不可能存在,ARM上READ得到返回值也不是0,依然是-1! 下面添加主函数代码。不久将放程序清单。 > int main(void) { int fd; int nread; char buff[2]; char *dev ="/dev/ttySAC0"; fd = OpenDev(dev); if (fd>0) set_speed(fd,9600); //打开后设置波特率9600 else { printf("Can't Open Serial Port!\n"); exit(0); } if (set_Parity(fd,8,1,'N')== FALSE) //设置8,1,n 注意,这里和上面要和下位机相符才可能通信 { printf("Set Parity Error\n"); exit(1); } fcntl(fd,F_SETFL,FNDELAY);//UNBLOCK while(1) { if(read(fd,buff,1)<0){printf("Read Error\n");} while((nread = read(fd,buff,1))>0) { printf("\nLen %d\n",nread); buff[nread+1]='\0'; printf(" Ken %s",buff); tcflush(fd, TCIOFLUSH);//读完再度清洗 } }
Linux下select函数关于集合和返回值的问题
FD_ZERO(&allset); FD_SET(listenfd, &allset); /* 构造select监控文件描述符集 */ while (1) { rset = allset; /* 每次循环时都从新设置select监控信号集 */ nready = select(maxfd+1, &rset, NULL, NULL, NULL); //2 1--lfd 1--connfd if (nready < 0) perr_exit("select error"); if (FD_ISSET(listenfd, &rset)) { /* 说明有新的客户端链接请求 */ clie_addr_len = sizeof(clie_addr); connfd = Accept(listenfd, (struct sockaddr *)&clie_addr, &clie_addr_len); /* Accept 不会阻塞 */ printf("received from %s at PORT %d\n", inet_ntop(AF_INET, &clie_addr.sin_addr, str, sizeof(str)), ntohs(clie_addr.sin_port)); for (i = 0; i < FD_SETSIZE; i++) if (client[i] < 0) { /* 找client[]中没有使用的位置 */ client[i] = connfd; /* 保存accept返回的文件描述符到client[]里 */ break; } if (i == FD_SETSIZE) { /* 达到select能监控的文件个数上限 1024 */ fputs("too many clients\n", stderr); exit(1); } FD_SET(connfd, &allset); /* 向监控文件描述符集合allset添加新的文件描述符connfd */ if (connfd > maxfd) maxfd = connfd; /* select第一个参数需要 */ if (i > maxi) maxi = i; /* 保证maxi存的总是client[]最后一个元素下标 */ if (--nready == 0) continue; } for (i = 0; i <= maxi; i++) { /* 检测哪个clients 有数据就绪 */ if ((sockfd = client[i]) < 0) continue; if (FD_ISSET(sockfd, &rset)) { if ((n = Read(sockfd, buf, sizeof(buf))) == 0) { /* 当client关闭链接时,服务器端也关闭对应链接 */ Close(sockfd); FD_CLR(sockfd, &allset); /* 解除select对此文件描述符的监控 */ client[i] = -1; } else if (n > 0) { for (j = 0; j < n; j++) buf[j] = toupper(buf[j]); Write(sockfd, buf, n); Write(STDOUT_FILENO, buf, n); } if (--nready == 0) break; /* 跳出for, 但还在while中 */ } } } 我一直想不明白 在第一次进入循环的时候select的返回值会是什么(假设有连接请求),但是因为rset中只有一个listenfd(监听套接字),那么在下面第二个判断 if (FD_ISSET(sockfd, &rset)) 的时候,sockfd怎么会在rset中呢?明明前面的处理调用是把clientfd放到了allset中,我主要是在这里不明白,已经在网上找了几个小时了,还是不清楚,所以才来特地求问,希望可以回复下,主要是想知道,select返回的时候,读集合中是怎么变化的,因为初始化读集合明明只有listenfd,在下面的判断中却是在判断sockfd是否在rset中,这一点表示十分疑惑。
汇编系统调用read读取文件返回值为-14
```.section .data name: .ascii "flags" name_end: .equ len,name_end-name .section .text .globl _start _start: push %rbp mov %rsp,%rbp sub $140,%rsp mov $5,%rax movl $0,%ecx movl $name,%ebx int $0x80 movl %eax,-8(%rbp) mov $100,%dl lea -132(%rbp),%rcx movl -8(%rbp),%ebx movl $3,%eax int $0x80 movl $4,%eax movl $100,%edx lea -132(%rbp),%rcx movl $1,%ebx int $0x80 movl $1,%eax mov $1,%ebx int $0x80 ``` 正在写一个汇编程序能够读取flag中的文件内容,运行起来总是失败,虽然open函数执行 成功并且返回值是3,但是read系统调用总是不成功,返回值总是-14,关键是写一个c 程序读取文件就没有问题,始终不知道这个写法错在哪里,求指教。 ``` ```
PEM_read_bio_RSAPrivateKey的返回值为NULL
我是要用OPENSSL编写私钥解密部分,但在使用函数PEM_read_bio_RSAPrivateKey()的返回值为NULL。 以下是我的代码: void rsadecrption(unsigned char cipher[],CString Path) {CFile fc; CFileException e; if(!fc.Open(Path,CFile::modeCreate | CFile::modeWrite|CFile::shareExclusive|CFile::typeBinary,&e)) { //AfxMessageBox("打开fp失败"); return; } EVP_PKEY* evpkey; RSA *rsa=NULL; BIO *key = NULL; unsigned long len; char dir[2048]={NULL}; memcpy(dir,Path,1024); //ques for(int i=0;i<1024;i++) { if(i%2==0) dir[i/2]=dir[i]; } ERR_load_crypto_strings(); //from Internet key = BIO_new(BIO_s_file()); BIO_read_filename(key,dir); rsa = PEM_read_bio_RSAPrivateKey(key, NULL, NULL, NULL); //返回值为NULL BIO_free_all(key); if(rsa==NULL){ printf("unable to read private key!\n"); return; } len = RSA_size( rsa ); unsigned char sign[4096]={NULL}; //int Len=strlen(cipher); int block=1024/256; //int remain=1024%256; for(int i=0;i<block;i++) { if(RSA_private_decrypt(256,sign,cipher,rsa,RSA_PKCS1_PADDING)<=0) return; fc.Write(sign,128); } //fwrite(cipher,strlen(sign),1,fc); fc.Close(); }
如何返回结构体指针?
小白新学链表 想用函数来表达一下 在函数返回值的地方遇到麻烦 请大佬们帮助 ``` typedef struct student { char name[10]; int num; struct scan { int speach; int read; int write; int hear; }SCAN; struct student *next; }STUDENT; ``` 用函数创建一个链表后 想返回头节点 如何以STUDENT* 返回函数值 ``` STUDENT* creatlink() { char name[10],*t; int i, n, num, s, r, w, h; STUDENT *head, *p, *q; printf("输入要录入的人数:"); scanf("%d", &n); printf("请依次录入学生的学号 姓名 及听说读写的分数"); head = NULL; q = NULL; for (i = 0; i < n; i++) { p = (STUDENT *)malloc(sizeof(STUDENT)); scanf("%d%s%d%d%d%d", &num, name, &s, &r, &w, &h); p->num = num; strcpy(p->name,name); p->SCAN.speach = s; p->SCAN.hear = h; p->SCAN.read = r; p->SCAN.write = w; if (head == NULL) head = p; else q->next = p; q = p; } return *head; } ``` 编译时在 return *head; *号上 说 不存在从 STUDENT 到STUDENT* 的适当转换函数 然后我删掉返回值上的*(return *head;) 后 输出的函数又不能用了 求大佬帮助 全部代码在下面 ``` #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct student { char name[10]; int num; struct scan { int speach; int read; int write; int hear; }SCAN; struct student *next; }STUDENT; STUDENT* creatlink() { char name[10],*t; int i, n, num, s, r, w, h; STUDENT *head, *p, *q; printf("输入要录入的人数:"); scanf("%d", &n); printf("请依次录入学生的学号 姓名 及听说读写的分数"); head = NULL; q = NULL; for (i = 0; i < n; i++) { p = (STUDENT *)malloc(sizeof(STUDENT)); scanf("%d%s%d%d%d%d", &num, name, &s, &r, &w, &h); p->num = num; strcpy(p->name,name); p->SCAN.speach = s; p->SCAN.hear = h; p->SCAN.read = r; p->SCAN.write = w; if (head == NULL) head = p; else q->next = p; q = p; } return *head; } void putlink(STUDENT *HEAD) { STUDENT *t; t = HEAD; while (t != NULL) { printf("%d\t%s\t听%d,说%d,读%d,写%d", t->num, t->name, t->SCAN.hear, t->SCAN.speach, t->SCAN.read, t->SCAN.write); t = t + 1; } } int main() { STUDENT *HEAD; HEAD = NULL; putlink(creatlink()); return 0; } ```
vc2010下串口函数返回值无效的问题(关闭后再打开即无效)
原来vc6下的代码,可以正常使用,现在移植到2010和2013下,问题出现,具体描述如下: 因为要读取一个设备的数据(该数据由软件操作控制发送数据,可持续不断以一定格式发);vc2010环境,用API函数(createfile)打开串口,期间用afxbeginthread开启了一个线程,运行进程函数,该函数主要为只要联机变量为真(连上了串口),就等待串口的字符串,然后把字符串放到缓存,回调函数完成字符串的处理和显示。 现在,当我第一次打开串口(没有连设备,只是用一根USB-RS232线转了一个串口),正常打开,关闭后(CloseHandle函数)再次打开,createfile返回的句柄即显示无效:错误代码6,句柄为0xfffffff。只能重新运行程序,然后还是第一次正常打开,关闭后即无法打开! ```打开串口,并启动线程 BOOL CComLink::NewConnection(BYTE nRetType, WORD UserID, BYTE nPort, LPVOID pOwner, LPVOID pParam) { if(m_bConnected) return FALSE; m_hCom = OpenConnection(CommProc, nPort); m_UserID = UserID; m_nRetType = nRetType; m_pWnd = (CWnd *)pOwner; m_pMsgFunc = (_CALLBACK_MSG *)pParam; return m_bConnected; } HANDLE CComLink::OpenConnection(AFX_THREADPROC pfnThreadProc, BYTE nPort) { HANDLE h_Com; wchar_t szPort[15]; COMMTIMEOUTS CommTimeOuts; wsprintf(szPort,_T("\\\\.\\COM%d"),nPort); h_Com = CreateFile(szPort,GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,NULL); if(h_Com == INVALID_HANDLE_VALUE) return NULL; else { SetCommMask(h_Com,EV_RXCHAR); SetupComm(h_Com,4096,4096); PurgeComm(h_Com, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR ); CommTimeOuts.ReadIntervalTimeout = MAXDWORD; CommTimeOuts.ReadTotalTimeoutMultiplier = 0; CommTimeOuts.ReadTotalTimeoutConstant = 1000; CommTimeOuts.WriteTotalTimeoutMultiplier = 0; CommTimeOuts.WriteTotalTimeoutConstant = 1000; SetCommTimeouts(h_Com, &CommTimeOuts); m_bConnected = true; } if(SetCom(h_Com)) { m_pThread = AfxBeginThread(pfnThreadProc, this, THREAD_PRIORITY_NORMAL, 0, 0, NULL); if(m_pThread == NULL) { CloseCom(); return NULL; } else { m_bConnected = true; } } else { CloseCom(); return NULL; } return h_Com; } ``` ```进程函数 UINT CommProc(LPVOID pParam) { DWORD dwMask = 0; COMSTAT ComStat; DWORD dwErrorFlags; DWORD dwLength; CComLink *pVoid=(CComLink*)pParam; SetCommMask(pVoid->m_hCom,EV_RXCHAR); while(pVoid->m_bConnected) { WaitCommEvent(pVoid->m_hCom, &dwMask, NULL); // 等待串口消息 if((dwMask & EV_RXCHAR)==EV_RXCHAR) // 如果是字符消息 { ClearCommError(pVoid->m_hCom, &dwErrorFlags, &ComStat); if(ComStat.cbInQue) { dwLength=min(sizeof(pVoid->m_DataBuf) - pVoid->m_nDataLen, ComStat.cbInQue); // 取缓冲区数据,确保分配的缓冲区能足够存储 if(!ReadFile(pVoid->m_hCom, &pVoid->m_DataBuf[pVoid->m_nDataLen], dwLength, &dwLength, &pVoid->osRead)) // 读取数据,存储到当前缓冲区位置之后 { if(GetLastError()==ERROR_IO_PENDING) { GetOverlappedResult(pVoid->m_hCom, &pVoid->osRead, &dwLength, true); } } pVoid->m_nDataLen += dwLength; // 数据长度累加 if(pVoid->m_nRetType == DATA_BY_MESSAGE) // 消息模式返回数据 { pVoid->m_pWnd -> SendMessage(WM_COM_RECMSG, pVoid->m_UserID); } else if(pVoid->m_nRetType == DATA_BY_CALLBACK) // 回调函数返回数据 { pVoid->m_pMsgFunc(WM_COM_RECMSG, (long)pVoid->m_pWnd, pVoid->m_UserID); } } }// end if } return 0; } ``` ```关闭串口 BOOL CComLink::CloseCom() { FindClose(m_hCom); CloseHandle(m_hCom); m_bConnected = false; m_hCom =INVALID_HANDLE_VALUE; return TRUE; } ``` ```设置串口 BOOL CComLink::SetCom(HANDLE h_Com) { DCB dcb; GetCommState(h_Com,&dcb); dcb.BaudRate = m_ComSet.BaudRate; dcb.ByteSize = m_ComSet.ByteSize; dcb.Parity = m_ComSet.Parity; dcb.StopBits = m_ComSet.StopBits; dcb.fRtsControl = RTS_CONTROL_ENABLE; return SetCommState(h_Com,&dcb); } ```
消息队列msgget函数返回值一直都是0,创建的消息队列只在第一次开机正常运行
使用msgget函数创建了一个消息队列,但是函数msgget无论每次运行都是返回0. 而且在删除消息队列后再次创建时,使用ipcs -q 命令查看时,可以看到mqid是32767,但是msgget函数的返回值依然是0,并且此时消息队列无法正常收发信息,在函数msgsnd处报错individual argument。此时重启虚拟机,再次运行不会报错,mqid依然是0 #define MAX_SEND_SIZE 80 struct mymsgbuf{ long mtype; char mtext[MAX_SEND_SIZE]; }; void send_message(int qid,struct mymsgbuf *qbuf,long type,char *text); void read_message(int qid,struct mymsgbuf *qbuf,long type); void remove_queue(int qid); void change_queue_mode(int qid,char *mode); void usage(); int main(int argc,char *argv[]){ key_t key; int msgqueue_id; struct mymsgbuf qbuf; if(argc ==1) usage(); /*Create unique key via call to ftok()*/ key = ftok(".", 2 ); if( msgqueue_id = msgget( key,IPC_CREAT | 0660) == -1){ perror("msgget\n"); exit(1); } printf("message queue id = [%d]\nkey = %d",msgqueue_id,key); switch(tolower(argv[1][0])) { case 's': if( argc < 4 ){ usage(); break; } send_message(msgqueue_id,(struct mymsgbuf*)&qbuf,atol(argv[2]),argv[3]); break; case 'r': if( argc < 3 ){ usage(); break; } read_message(msgqueue_id,&qbuf,atol(argv[2])); break; case 'm': if( argc < 3 ){ usage(); break; } change_queue_mode(msgqueue_id,argv[2]); break; case 'd': remove_queue(msgqueue_id); break; default: usage(); } return (0); } void send_message(int qid,struct mymsgbuf *qbuf,long type,char *text) { //Send a message to the queue printf("Sending a message ...\n"); qbuf->mtype = type; strcpy(qbuf->mtext,text); if((msgsnd(qid,(struct msgbuf *)qbuf,strlen(qbuf->mtext)+1,0)) == -1){ perror("msgsnd"); exit(1); } } void read_message(int qid,struct mymsgbuf *qbuf,long type){ //Read a message from the queue printf("Reading a message ...\n"); qbuf->mtype = type; msgrcv(qid,(struct msgbuf*)qbuf,MAX_SEND_SIZE,type,0); printf("Type:%ld\nText:%s\n",qbuf->mtype,qbuf->mtext); } void remove_queue(int qid){ msgctl(qid,IPC_RMID,0); } void change_queue_mode(int qid,char *mode) { struct msqid_ds myqueue_ds; //Get current info msgctl(qid,IPC_STAT,&myqueue_ds); //Convert and load the mode sscanf(mode,"%ho",&myqueue_ds.msg_perm.mode); //Update the mode msgctl(qid,IPC_SET,&myqueue_ds); } void usage(void) { fprintf(stderr,"msgtool -A utility for tinkering with msgqueues\n"); fprintf(stderr,"Usage:msgtool (s)end<type> <messagetext>\n"); fprintf(stderr,"(r)ecv <type>\n"); fprintf(stderr,"(d)elete\n"); fprintf(stderr,"(m)ode <octal mode>\n"); exit(1); } ``` ``` ``` ```
python函数(有输入和输出)打包成exe后如何调用?
.py文件名为“read_result.py”,在打包为exe前,用read_result.getdata(file)调用getdata()函数可以得到该函数返回值。那么将read_result.py打包为exe怎么调用函数getdata(),并得到其fan'hui'zhi ``` import pickle def getdata(file): f = open(file, 'rb') data = pickle.load(f) name = [] .... .... .... return data, name if __name__ == '__main__': ```
Xposed开发 如何修改通过参数传值的函数的参数?
如题,比如我要HOOK一个函数 ![图片说明](https://img-ask.csdn.net/upload/201603/19/1458372035_286716.png) 其返回值是一个int类型,表示读取到byte[] b里面的内容的长度,而真正的内容在byte[] b里面,通过参数传递的。在函数执行前byte[] b是一个长度为1024的空数组。 执行后b读取到内容。 我想获取函数执行后b的内容并修改,但是失败了 ![图片说明](https://img-ask.csdn.net/upload/201603/19/1458372086_850358.png) 按道理来说第一次的log应当能记录下函数执行后b的实际值,即函数所要传递的内容,但是得到的却是长度为1024的空数组。 第二次log确实得到了修改后的“read method was hooked!!!!”,但是在应用中调用这个方法时并没有显示这句话,和hook之前一样。 我的想法是xposed只保存了函数调用前的参数,函数调用后无法再对参数做出变更。 那么请问我该如何达到我的目的?
C#中 使用windowsAPI writefile函数 返回一直FALSE
RT 项目需要 能够在SD卡的指定偏移位置写入数据,因此使用windowsAPI的 writefile函数 引用了kernel32.dll 转换的数据类型结果如下 [System.Runtime.InteropServices.DllImportAttribute("kernel32.dll", EntryPoint = "WriteFile", SetLastError = true, ThrowOnUnmappableChar = true)] [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)] public static extern unsafe bool WriteFile ( System.IntPtr hFile, void* lpBuffer, uint nNumberOfBytesToWrite, uint* lpNumberOfBytesWritten, int lpOverlapped ); 用createfile方法 以物理形式访问SD卡访问模式 为GENERIC_READ|GENERIC_WRITE,共享模式为FILE_SHARE_WRITE. 但最后调用的时候 总是写不进去 返回值始终为false 求大侠们指点!!!!!!!!
tensorflow 训练数据集时,报错InvalidArgumentError: Incompatible shapes: [15] vs. [15,6],标签的占位符与标签喂的数据格式不符,要怎么解决?
InvalidArgumentError (see above for traceback): Incompatible shapes: [15] vs. [15,6] 报错的详细信息如下所示: ``` INFO:tensorflow:Error reported to Coordinator: <class 'tensorflow.python.framework.errors_impl.CancelledError'>, Enqueue operation was cancelled [[Node: input_producer/input_producer_EnqueueMany = QueueEnqueueManyV2[Tcomponents=[DT_STRING], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](input_producer, input_producer/RandomShuffle)]] Caused by op 'input_producer/input_producer_EnqueueMany', defined at: File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\ipykernel_launcher.py", line 16, in <module> app.launch_new_instance() File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance app.start() File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\ipykernel\kernelapp.py", line 477, in start ioloop.IOLoop.instance().start() File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\zmq\eventloop\ioloop.py", line 177, in start super(ZMQIOLoop, self).start() File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tornado\ioloop.py", line 888, in start handler_func(fd_obj, events) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tornado\stack_context.py", line 277, in null_wrapper return fn(*args, **kwargs) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\zmq\eventloop\zmqstream.py", line 440, in _handle_events self._handle_recv() File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\zmq\eventloop\zmqstream.py", line 472, in _handle_recv self._run_callback(callback, msg) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\zmq\eventloop\zmqstream.py", line 414, in _run_callback callback(*args, **kwargs) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tornado\stack_context.py", line 277, in null_wrapper return fn(*args, **kwargs) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\ipykernel\kernelbase.py", line 283, in dispatcher return self.dispatch_shell(stream, msg) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\ipykernel\kernelbase.py", line 235, in dispatch_shell handler(stream, idents, msg) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\ipykernel\kernelbase.py", line 399, in execute_request user_expressions, allow_stdin) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\ipykernel\ipkernel.py", line 196, in do_execute res = shell.run_cell(code, store_history=store_history, silent=silent) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\ipykernel\zmqshell.py", line 533, in run_cell return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py", line 2698, in run_cell interactivity=interactivity, compiler=compiler, result=result) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py", line 2802, in run_ast_nodes if self.run_code(code, result): File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py", line 2862, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-19-6fa659dba762>", line 320, in <module> batch_test(data_path, 100, 100, n_batch, train_op, loss, acc, range_num, val_batch) File "<ipython-input-19-6fa659dba762>", line 147, in batch_test tf_image,tf_label = read_records(record_file,resize_height,resize_width,type='normalization') File "<ipython-input-19-6fa659dba762>", line 84, in read_records filename_queue = tf.train.string_input_producer([filename]) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\training\input.py", line 232, in string_input_producer cancel_op=cancel_op) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\training\input.py", line 164, in input_producer enq = q.enqueue_many([input_tensor]) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\ops\data_flow_ops.py", line 367, in enqueue_many self._queue_ref, vals, name=scope) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\ops\gen_data_flow_ops.py", line 1556, in _queue_enqueue_many_v2 name=name) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 768, in apply_op op_def=op_def) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 2336, in create_op original_op=self._default_original_op, op_def=op_def) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 1228, in __init__ self._traceback = _extract_stack() CancelledError (see above for traceback): Enqueue operation was cancelled [[Node: input_producer/input_producer_EnqueueMany = QueueEnqueueManyV2[Tcomponents=[DT_STRING], timeout_ms=-1, _device="/job:localhost/replica:0/task:0/cpu:0"](input_producer, input_producer/RandomShuffle)]] --------------------------------------------------------------------------- InvalidArgumentError Traceback (most recent call last) H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args) 1038 try: -> 1039 return fn(*args) 1040 except errors.OpError as e: H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py in _run_fn(session, feed_dict, fetch_list, target_list, options, run_metadata) 1020 feed_dict, fetch_list, target_list, -> 1021 status, run_metadata) 1022 H:\aa\Anaconda\anaconda\envs\tensorflow\lib\contextlib.py in __exit__(self, type, value, traceback) 87 try: ---> 88 next(self.gen) 89 except StopIteration: H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\framework\errors_impl.py in raise_exception_on_not_ok_status() 465 compat.as_text(pywrap_tensorflow.TF_Message(status)), --> 466 pywrap_tensorflow.TF_GetCode(status)) 467 finally: InvalidArgumentError: Incompatible shapes: [15] vs. [15,6] [[Node: Equal = Equal[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"](Cast_1, _recv_y__0/_21)]] [[Node: Mean/_25 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_177_Mean", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]] During handling of the above exception, another exception occurred: InvalidArgumentError Traceback (most recent call last) <ipython-input-19-6fa659dba762> in <module>() 318 range_num = 5 319 --> 320 batch_test(data_path, 100, 100, n_batch, train_op, loss, acc, range_num, val_batch) 321 <ipython-input-19-6fa659dba762> in batch_test(record_file, resize_height, resize_width, n_batch, train_op, loss, acc, range_num, val_batch) 187 images_x = np.reshape(images, (-1, 30000)) 188 labels_y = np.reshape(labels, (-1, 6)) --> 189 _,err,ac = sess.run([train_op,loss,acc],feed_dict={x:images, y_:labels_y}) # 50% 神经元在工作中 190 train_loss = train_loss + err 191 train_acc = train_acc + ac H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py in run(self, fetches, feed_dict, options, run_metadata) 776 try: 777 result = self._run(None, fetches, feed_dict, options_ptr, --> 778 run_metadata_ptr) 779 if run_metadata: 780 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr) H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata) 980 if final_fetches or final_targets: 981 results = self._do_run(handle, final_targets, final_fetches, --> 982 feed_dict_string, options, run_metadata) 983 else: 984 results = [] H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata) 1030 if handle is None: 1031 return self._do_call(_run_fn, self._session, feed_dict, fetch_list, -> 1032 target_list, options, run_metadata) 1033 else: 1034 return self._do_call(_prun_fn, self._session, handle, feed_dict, H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args) 1050 except KeyError: 1051 pass -> 1052 raise type(e)(node_def, op, message) 1053 1054 def _extend_graph(self): InvalidArgumentError: Incompatible shapes: [15] vs. [15,6] [[Node: Equal = Equal[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"](Cast_1, _recv_y__0/_21)]] [[Node: Mean/_25 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_177_Mean", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]] Caused by op 'Equal', defined at: File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\ipykernel_launcher.py", line 16, in <module> app.launch_new_instance() File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance app.start() File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\ipykernel\kernelapp.py", line 477, in start ioloop.IOLoop.instance().start() File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\zmq\eventloop\ioloop.py", line 177, in start super(ZMQIOLoop, self).start() File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tornado\ioloop.py", line 888, in start handler_func(fd_obj, events) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tornado\stack_context.py", line 277, in null_wrapper return fn(*args, **kwargs) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\zmq\eventloop\zmqstream.py", line 440, in _handle_events self._handle_recv() File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\zmq\eventloop\zmqstream.py", line 472, in _handle_recv self._run_callback(callback, msg) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\zmq\eventloop\zmqstream.py", line 414, in _run_callback callback(*args, **kwargs) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tornado\stack_context.py", line 277, in null_wrapper return fn(*args, **kwargs) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\ipykernel\kernelbase.py", line 283, in dispatcher return self.dispatch_shell(stream, msg) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\ipykernel\kernelbase.py", line 235, in dispatch_shell handler(stream, idents, msg) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\ipykernel\kernelbase.py", line 399, in execute_request user_expressions, allow_stdin) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\ipykernel\ipkernel.py", line 196, in do_execute res = shell.run_cell(code, store_history=store_history, silent=silent) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\ipykernel\zmqshell.py", line 533, in run_cell return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py", line 2698, in run_cell interactivity=interactivity, compiler=compiler, result=result) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py", line 2802, in run_ast_nodes if self.run_code(code, result): File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py", line 2862, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-19-6fa659dba762>", line 311, in <module> correct_prediction = tf.equal(tf.cast(tf.argmax(logits,1),tf.float32), y_) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\ops\gen_math_ops.py", line 672, in equal result = _op_def_lib.apply_op("Equal", x=x, y=y, name=name) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 768, in apply_op op_def=op_def) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 2336, in create_op original_op=self._default_original_op, op_def=op_def) File "H:\aa\Anaconda\anaconda\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 1228, in __init__ self._traceback = _extract_stack() InvalidArgumentError (see above for traceback): Incompatible shapes: [15] vs. [15,6] [[Node: Equal = Equal[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/gpu:0"](Cast_1, _recv_y__0/_21)]] [[Node: Mean/_25 = _Recv[client_terminated=false, recv_device="/job:localhost/replica:0/task:0/cpu:0", send_device="/job:localhost/replica:0/task:0/gpu:0", send_device_incarnation=1, tensor_name="edge_177_Mean", tensor_type=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"]()]] ``` x,y- 占位符打印的信息如下: ``` x: Tensor("x-input:0", shape=(?, 100, 100, 3), dtype=float32) y_:Tensor("y_:0", shape=(?, 6), dtype=float32) ``` image 和 labels 的打印信息如下: ``` shape:(15, 100, 100, 3),tpye:float32,labels:[[ 0. 0. 0. 1. 0. 0.] [ 0. 0. 0. 1. 0. 0.] [ 0. 0. 0. 1. 0. 0.] [ 0. 0. 0. 0. 1. 0.] [ 1. 0. 0. 0. 0. 0.] [ 0. 0. 0. 1. 0. 0.] [ 1. 0. 0. 0. 0. 0.] [ 1. 0. 0. 0. 0. 0.] [ 1. 0. 0. 0. 0. 0.] [ 0. 0. 0. 0. 0. 1.] [ 0. 0. 1. 0. 0. 0.] [ 1. 0. 0. 0. 0. 0.] [ 1. 0. 0. 0. 0. 0.] [ 0. 0. 0. 0. 1. 0.] [ 0. 0. 0. 0. 1. 0.]] ``` 整个运行的代码如下: ``` import tensorflow as tf import numpy as np import os import cv2 import matplotlib.pyplot as plt import random import time from PIL import Image os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' data_path = 'people_pictures_train/record/one_train_demo_people_train.tfrecords' # tfrecords 文件的地址 data_path_val = 'people_pictures_train/record/one_test_demo_people_val.tfrecords' # tfrecords 文件的地址 print("----------------------------") tf.reset_default_graph() def get_example_nums(tf_records_filenames): ''' 统计tf_records图像的个数(example)个数 :param tf_records_filenames: tf_records文件路径 :return: ''' nums= 0 for record in tf.python_io.tf_record_iterator(tf_records_filenames): nums += 1 return nums def show_image(title,image): ''' 显示图片 :param title: 图像标题 :param image: 图像的数据 :return: ''' # plt.figure("show_image") # print(image.dtype) plt.imshow(image) plt.axis('on') # 关掉坐标轴为 off plt.title(title) # 图像题目 plt.show() def get_batch_images(images,labels,batch_size,labels_nums,one_hot=False,shuffle=False,num_threads=1): ''' :param images:图像 :param labels:标签 :param batch_size: :param labels_nums:标签个数 :param one_hot:是否将labels转为one_hot的形式 :param shuffle:是否打乱顺序,一般train时shuffle=True,验证时shuffle=False :return:返回batch的images和labels ''' min_after_dequeue = 200 capacity = min_after_dequeue + 3 * batch_size # 保证capacity必须大于min_after_dequeue参数值 if shuffle: images_batch, labels_batch = tf.train.shuffle_batch([images,labels], batch_size=batch_size, capacity=capacity, min_after_dequeue=min_after_dequeue, num_threads=num_threads) else: images_batch, labels_batch = tf.train.batch([images,labels], batch_size=batch_size, capacity=capacity, num_threads=num_threads) if one_hot: labels_batch = tf.one_hot(labels_batch, labels_nums, 1, 0) return images_batch,labels_batch def read_records(filename,resize_height, resize_width,type=None): ''' 解析record文件:源文件的图像数据是RGB,uint8,[0,255],一般作为训练数据时,需要归一化到[0,1] :param filename: :param resize_height: :param resize_width: :param type:选择图像数据的返回类型 None:默认将uint8-[0,255]转为float32-[0,255] normalization:归一化float32-[0,1] standardization:归一化float32-[0,1],再减均值中心化 :return: ''' # 创建文件队列,不限读取的数量 filename_queue = tf.train.string_input_producer([filename]) # create a reader from file queue reader = tf.TFRecordReader() # reader从文件队列中读入一个序列化的样本 _, serialized_example = reader.read(filename_queue) # get feature from serialized example # 解析符号化的样本 features = tf.parse_single_example( serialized_example, features={ 'image_raw': tf.FixedLenFeature([], tf.string), 'height': tf.FixedLenFeature([], tf.int64), 'width': tf.FixedLenFeature([], tf.int64), 'depth': tf.FixedLenFeature([], tf.int64), 'labels': tf.FixedLenFeature([], tf.string) } ) tf_image = tf.decode_raw(features['image_raw'], tf.uint8)#获得图像原始的数据 tf_height = features['height'] tf_width = features['width'] tf_depth = features['depth'] # tf_label = tf.cast(features['labels'], tf.float32) tf_label = tf.decode_raw(features['labels'],tf.float32) # PS:恢复原始图像数据,reshape的大小必须与保存之前的图像shape一致,否则出错 # tf_image=tf.reshape(tf_image, [-1]) # 转换为行向量 tf_image=tf.reshape(tf_image, [resize_height, resize_width, 3]) # 设置图像的维度 tf_label=tf.reshape(tf_label, [6]) # 设置图像的维度 # 恢复数据后,才可以对图像进行resize_images:输入uint->输出float32 # tf_image=tf.image.resize_images(tf_image,[224, 224]) # [3]数据类型处理 # 存储的图像类型为uint8,tensorflow训练时数据必须是tf.float32 if type is None: tf_image = tf.cast(tf_image, tf.float32) elif type == 'normalization': # [1]若需要归一化请使用: # 仅当输入数据是uint8,才会归一化[0,255] # tf_image = tf.cast(tf_image, dtype=tf.uint8) # tf_image = tf.image.convert_image_dtype(tf_image, tf.float32) tf_image = tf.cast(tf_image, tf.float32) * (1. / 255.0) # 归一化 elif type == 'standardization': # 标准化 # tf_image = tf.cast(tf_image, dtype=tf.uint8) # tf_image = tf.image.per_image_standardization(tf_image) # 标准化(减均值除方差) # 若需要归一化,且中心化,假设均值为0.5,请使用: tf_image = tf.cast(tf_image, tf.float32) * (1. / 255) - 0.5 # 中心化 # 这里仅仅返回图像和标签 # return tf_image, tf_height,tf_width,tf_depth,tf_label return tf_image,tf_label def batch_test(record_file,resize_height,resize_width,n_batch,train_op,loss,acc,range_num,val_batch): ''' :param record_file: record文件路径 :param resize_height: :param resize_width: :return: :PS:image_batch, label_batch一般作为网络的输入 ''' # 读取record函数 tf_image,tf_label = read_records(record_file,resize_height,resize_width,type='normalization') image_batch, label_batch= get_batch_images(tf_image,tf_label,batch_size=15,labels_nums=6,one_hot=False,shuffle=True) a = image_batch.get_shape() a2 = a.as_list() b = label_batch.get_shape() b2 = b.as_list() print('image_batch: '+ str(image_batch) + ' label_batch: ' + str(label_batch)) print('image_batch-len:' + str(len(a2)) + ' label_batch-len: ' + str(len(b2))) # 测试的数据 images_val,labels_val = read_records(data_path_val,100,100,type='normalization') image_batch_val, label_batch_val = get_batch_images(images_val,labels_val,batch_size=15,labels_nums=6,one_hot=False,shuffle=True) # print('image_batch_val: '+ str(image_batch_val) + ' label_batch_val: ' + str(label_batch_val)) init = tf.global_variables_initializer() with tf.Session() as sess: # 开始一个会话 sess.run(init) # train_writer = tf.summary.FileWriter('logs/train',sess.graph) # 当前目录下的 logs 文件夹,如果没有这个文件夹,会自己键, 写入graph 的图 # test_writer = tf.summary.FileWriter('logs/test',sess.graph) # 当前目录下的 logs 文件夹,如果没有这个文件夹,会自己键, 写入graph 的图 coord = tf.train.Coordinator() threads = tf.train.start_queue_runners(coord=coord) for epoch in range(range_num) : start_time = time.time() train_loss, train_acc = 0,0 for i in range(n_batch): images, labels = sess.run([image_batch, label_batch]) print('shape:{},tpye:{},labels:{}'.format(images.shape,images.dtype,labels)) print('images-len:' + str(len(images)) + ' labels-len: ' + str(len(labels))) for i in range(len(images)): show_image("image0", images[i, :, :, :]) a = np.zeros( (len(labels)) ) print(' a: ' +str(a)) for i in range(len(labels)): for j in range(len(labels[i])): if labels[i][j] > 0: a[i] = j print(' a: ' +str(a)) print('x: ' + str(x) + ' y_:' + str(y_)) images_x = np.reshape(images, (-1, 30000)) labels_y = np.reshape(labels, (-1, 6)) _,err,ac = sess.run([train_op,loss,acc],feed_dict={x:images, y_:labels_y}) # 50% 神经元在工作中 train_loss = train_loss + err train_acc = train_acc + ac print(" train loss: %f" % (np.sum(train_err)/n_batch)) print(" train acc: %f" % (np.sum(train_acc)/n_batch)) val_loss, val_acc = 0, 0 for i in range(val_batch): # test 在会话中取出images和labels测试数据, images_val2 主要是为了与 images_val 进行区分 images_val2, labels_val2 = sess.run([image_batch_val, label_batch_val]) val_loss, val_acc = sess.run([loss,acc], feed_dict={x:images_val_x, y_:labels_val2}) # 测试一下准确率,喂的数据是,图片和图片的标签 val_loss = val_loss + err val_acc = val_acc + ac print(" validation loss: %f" % (np.sum(val_loss)/val_batch)) print(" validation acc: %f" % (np.sum(val_acc)/val_batch)) # 停止所有线程 coord.request_stop() coord.join(threads) # 每个批次的大小 batch_size = 15 #每个批次 10,一次性放入100张图,放到神经网络中进行训练,以矩阵的形式放入 # 计算一共有多少个批次 # n_batch = mnist.train.num_examples // batch_size #整除 n_batch = get_example_nums(data_path) // batch_size val_batch = get_example_nums(data_path_val) // batch_size # 测试图片的数量 转换格式时以一个batch 放所有的图片 # val_num = get_example_nums(data_path_val) # 测试图片的数量 转换格式时以一个batch 放所有的图片 # train_num = get_example_nums(data_path) # 测试图片的数量 转换格式时以一个batch 放所有的图片 print ("-----------------" + str(n_batch) + " batch------------") #将所有的图片resize成100*100 w=100 h=100 c=3 #-----------------构建网络---------------------- #占位符 #-----------------构建网络---------------------- #占位符 x = tf.placeholder(tf.float32,[None,100,100,3],name='x-input') #图片像素 转换 一维向量,行与批次有关,none 代表行,列是784 y_=tf.placeholder(tf.float32,shape=[None,6],name='y_') def inference(input_tensor, train, regularizer): with tf.variable_scope('layer1-conv1'): conv1_weights = tf.get_variable("weight",[5,5,3,32],initializer=tf.truncated_normal_initializer(stddev=0.1)) conv1_biases = tf.get_variable("bias", [32], initializer=tf.constant_initializer(0.0)) conv1 = tf.nn.conv2d(input_tensor, conv1_weights, strides=[1, 1, 1, 1], padding='SAME') relu1 = tf.nn.relu(tf.nn.bias_add(conv1, conv1_biases)) with tf.name_scope("layer2-pool1"): pool1 = tf.nn.max_pool(relu1, ksize = [1,2,2,1],strides=[1,2,2,1],padding="VALID") with tf.variable_scope("layer3-conv2"): conv2_weights = tf.get_variable("weight",[5,5,32,64],initializer=tf.truncated_normal_initializer(stddev=0.1)) conv2_biases = tf.get_variable("bias", [64], initializer=tf.constant_initializer(0.0)) conv2 = tf.nn.conv2d(pool1, conv2_weights, strides=[1, 1, 1, 1], padding='SAME') relu2 = tf.nn.relu(tf.nn.bias_add(conv2, conv2_biases)) with tf.name_scope("layer4-pool2"): pool2 = tf.nn.max_pool(relu2, ksize=[1, 2 , 2, 1], strides=[1, 2, 2, 1], padding='VALID') with tf.variable_scope("layer5-conv3"): conv3_weights = tf.get_variable("weight",[3,3,64,128],initializer=tf.truncated_normal_initializer(stddev=0.1)) conv3_biases = tf.get_variable("bias", [128], initializer=tf.constant_initializer(0.0)) conv3 = tf.nn.conv2d(pool2, conv3_weights, strides=[1, 1, 1, 1], padding='SAME') relu3 = tf.nn.relu(tf.nn.bias_add(conv3, conv3_biases)) with tf.name_scope("layer6-pool3"): pool3 = tf.nn.max_pool(relu3, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='VALID') with tf.variable_scope("layer7-conv4"): conv4_weights = tf.get_variable("weight",[3,3,128,128],initializer=tf.truncated_normal_initializer(stddev=0.1)) conv4_biases = tf.get_variable("bias", [128], initializer=tf.constant_initializer(0.0)) conv4 = tf.nn.conv2d(pool3, conv4_weights, strides=[1, 1, 1, 1], padding='SAME') relu4 = tf.nn.relu(tf.nn.bias_add(conv4, conv4_biases)) with tf.name_scope("layer8-pool4"): pool4 = tf.nn.max_pool(relu4, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='VALID') nodes = 6*6*128 reshaped = tf.reshape(pool4,[-1,nodes]) with tf.variable_scope('layer9-fc1'): fc1_weights = tf.get_variable("weight", [nodes, 1024], initializer=tf.truncated_normal_initializer(stddev=0.1)) if regularizer != None: tf.add_to_collection('losses', regularizer(fc1_weights)) fc1_biases = tf.get_variable("bias", [1024], initializer=tf.constant_initializer(0.1)) fc1 = tf.nn.relu(tf.matmul(reshaped, fc1_weights) + fc1_biases) if train: fc1 = tf.nn.dropout(fc1, 0.5) with tf.variable_scope('layer10-fc2'): fc2_weights = tf.get_variable("weight", [1024, 512], initializer=tf.truncated_normal_initializer(stddev=0.1)) if regularizer != None: tf.add_to_collection('losses', regularizer(fc2_weights)) fc2_biases = tf.get_variable("bias", [512], initializer=tf.constant_initializer(0.1)) fc2 = tf.nn.relu(tf.matmul(fc1, fc2_weights) + fc2_biases) if train: fc2 = tf.nn.dropout(fc2, 0.5) with tf.variable_scope('layer11-fc3'): fc3_weights = tf.get_variable("weight", [512, 6], initializer=tf.truncated_normal_initializer(stddev=0.1)) if regularizer != None: tf.add_to_collection('losses', regularizer(fc3_weights)) fc3_biases = tf.get_variable("bias", [6], initializer=tf.constant_initializer(0.1)) logit = tf.matmul(fc2, fc3_weights) + fc3_biases return logit #---------------------------网络结束--------------------------- regularizer = tf.contrib.layers.l2_regularizer(0.0001) logits = inference(x,False,regularizer) #(小处理)将logits乘以1赋值给logits_eval,定义name,方便在后续调用模型时通过tensor名字调用输出tensor b = tf.constant(value=1,dtype=tf.float32) logits_eval = tf.multiply(logits,b,name='logits_eval') # loss=tf.nn.sparse_softmax_cross_entropy_with_logits(logits=logits, labels=y_) loss = tf.nn.softmax_cross_entropy_with_logits(labels=y_, logits=logits) train_op=tf.train.AdamOptimizer(learning_rate=0.001).minimize(loss) correct_prediction = tf.equal(tf.cast(tf.argmax(logits,1),tf.float32), y_) acc= tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) print("----------------------------") if __name__ == '__main__': range_num = 5 batch_test(data_path, 100, 100, n_batch, train_op, loss, acc, range_num, val_batch) ```
安卓调用百度地图sdk,可是返回坐标值一直是4.9E-324
我发现手机端使用正常,就是在使用夜神模拟器的时候出现的这样的问题。 打开夜神模拟器设置,发现我的软件有这个位置权限(手机端申请了动态权限) 但就是返回4.9E-324,location.getLocType()的返回值是167.我看文档说是没有获取到位置权限。 我现在就有一点迷惑了,动态的也申请了,也在AndroidManifest里面写了权限。 真心不知道这个bug咋解决。 以下是我mainactivity里面所有的代码: ``` package com.example.ppgo; import android.Manifest; import android.content.pm.PackageManager; import android.os.Bundle; import android.util.Log; import android.widget.TextView; import android.widget.Toast; import com.baidu.location.BDLocation; import com.baidu.location.BDLocationListener; import com.baidu.location.LocationClient; import com.baidu.location.LocationClientOption; import java.util.ArrayList; import java.util.List; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; public class MainActivity extends AppCompatActivity { public LocationClient mLocationClient; private TextView positionText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mLocationClient=new LocationClient(getApplicationContext()); mLocationClient.registerLocationListener(new MyLocationListener()); setContentView(R.layout.activity_main); positionText=(TextView)findViewById(R.id.position_text_view); List<String> permissionList=new ArrayList<>(); if(ContextCompat.checkSelfPermission(MainActivity.this, Manifest. permission.ACCESS_FINE_LOCATION)!=PackageManager.PERMISSION_GRANTED){ permissionList.add(Manifest.permission.ACCESS_FINE_LOCATION); } if(ContextCompat.checkSelfPermission(MainActivity.this, Manifest. permission.READ_PHONE_STATE)!=PackageManager.PERMISSION_GRANTED){ permissionList.add(Manifest.permission.READ_PHONE_STATE); } if(ContextCompat.checkSelfPermission(MainActivity.this, Manifest. permission.WRITE_EXTERNAL_STORAGE)!=PackageManager.PERMISSION_GRANTED){ permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); } if(!permissionList.isEmpty()){ String[]permissions=permissionList.toArray(new String[permissionList.size()]); ActivityCompat.requestPermissions(MainActivity.this,permissions,1); }else { requestLocation(); } } private void requestLocation(){ initLocation(); mLocationClient.start(); } private void initLocation(){ LocationClientOption option =new LocationClientOption(); option.setScanSpan(5000); mLocationClient.setLocOption(option); } @Override protected void onDestroy() { super.onDestroy(); mLocationClient.stop(); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); Log.e("Tag","执行了onRequestPermissionsResult函数"); switch (requestCode){ case 1: if (grantResults.length>0){ for(int result:grantResults){ if(result!=PackageManager.PERMISSION_GRANTED){ Toast.makeText(this,"必须同意所有权限才能使用本程序", Toast.LENGTH_SHORT).show(); finish(); return; } } requestLocation(); }else { Toast.makeText(this,"发生未知错误",Toast.LENGTH_SHORT).show(); finish(); } break; default: } } public class MyLocationListener implements BDLocationListener { @Override public void onReceiveLocation(BDLocation location){ StringBuilder currentPosition=new StringBuilder(); currentPosition.append("纬度:").append(location.getLatitude()).append("\n"); currentPosition.append("经线:").append(location.getLongitude()).append("\n"); currentPosition.append("国家:").append(location.getCountry()).append("\n"); currentPosition.append("省:").append(location.getProvince()).append("\n"); currentPosition.append("市:").append(location.getCity()).append("\n"); currentPosition.append("区:").append(location.getDistrict()).append("\n"); currentPosition.append("街道:").append(location.getStreet()).append("\n"); currentPosition.append("定位方式:"); if (location.getLocType() == BDLocation.TypeGpsLocation) { currentPosition.append("GPS"); } else if (location.getLocType() == BDLocation.TypeNetWorkLocation) { currentPosition.append("网络"); currentPosition.append(" 错误代码:"+location.getLocType()); } else if (location.getLocType() == BDLocation.TypeOffLineLocation){ currentPosition.append("离线定位成功,离线定位结果也是有效的"); } else if (location.getLocType() == BDLocation.TypeServerError){ currentPosition.append("服务端网络定位失败"); currentPosition.append(" 错误代码:"+location.getLocType()); } else if (location.getLocType() == BDLocation.TypeNetWorkException){ currentPosition.append("网络不同导致定位失败,请检查网络是否通畅"); } else if (location.getLocType() == BDLocation.TypeCriteriaException){ currentPosition.append("无法获取有效定位依据导致定位失败"); currentPosition.append(" 错误代码:"+location.getLocType()); } else { currentPosition.append(location.getLocType()); //这里打印出来location.getLocType()是162 currentPosition.append("老子也不知道是啥原因!!!"); } positionText.setText(currentPosition); } } } ``` 以下是我AndroidManifest里面的代码: ``` <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.ppgo"> <!-- 这个权限用于进行网络定位 --> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <!-- 这个权限用于访问GPS定位 --> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <!-- 用于访问wifi网络信息,wifi信息会用于进行网络定位 --> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <!-- 获取网络状态,根据网络状态切换进行数据请求网络转换 --> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- 写外置存储。如果开发者使用了离线地图,并且数据写在外置存储区域,则需要申请该权限 --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- 读取外置存储。如果开发者使用了so动态加载功能并且把so文件放在了外置存储区域,则需要申请该权限,否则不需要 --> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <!-- 访问网络,进行地图相关业务数据请求,包括地图数据,路线规划,POI检索等 --> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <meta-data android:name="com.baidu.lbsapi.API_KEY" android:value="mvxMsdG1homIlK4UjAWYP2itjxo09Dyy" /> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <service android:name="com.baidu.location.f" android:enabled="true" android:process=":remote" /> </application> </manifest> ```
minst深度学习例程不收敛,成功率始终在十几
minst深度学习程序不收敛 是关于tensorflow的问题。我是tensorflow的初学者。从书上抄了minst的学习程序。但是运行之后,无论学习了多少批次,成功率基本不变。 我做了许多尝试,去掉了正则化,去掉了滑动平均,还是不行。把batch_size改成了2,观察变量运算情况,输入x是正确的,但神经网络的输出y很多情况下在x不一样的情况下y的两个结果是完全一样的。进而softmax的结果也是一样的。百思不得其解,找不到造成这种情况的原因。这里把代码和运行情况都贴出来,请大神帮我找找原因。大过年的,祝大家春节快乐万事如意。 补充一下,进一步的测试表明,不是不能完成训练,而是要到700000轮以上,且最高达到65%左右就不能提高了。仔细看每一步的参数,是regularization值过大10e15以上,一点点减少,前面的训练都在训练它了。这东西我不是很明白。 ``` import struct import numpy as np import matplotlib.pyplot as plt from matplotlib.widgets import Slider, Button import tensorflow as tf import time #把MNIST的操作封装在一个类中,以后用起来方便。 class MyMinst(): def decode_idx3_ubyte(self,idx3_ubyte_file): with open(idx3_ubyte_file, 'rb') as f: print('解析文件:', idx3_ubyte_file) fb_data = f.read() offset = 0 fmt_header = '>iiii' # 以大端法读取4个 unsinged int32 magic_number, num_images, num_rows, num_cols = struct.unpack_from(fmt_header, fb_data, offset) print('idex3 魔数:{},图片数:{}'.format(magic_number, num_images)) offset += struct.calcsize(fmt_header) fmt_image = '>' + str(num_rows * num_cols) + 'B' images = np.empty((num_images, num_rows*num_cols)) #做了修改 for i in range(num_images): im = struct.unpack_from(fmt_image, fb_data, offset) images[i] = np.array(im)#这里用一维数组表示图片,np.array(im).reshape((num_rows, num_cols)) offset += struct.calcsize(fmt_image) return images def decode_idx1_ubyte(self,idx1_ubyte_file): with open(idx1_ubyte_file, 'rb') as f: print('解析文件:', idx1_ubyte_file) fb_data = f.read() offset = 0 fmt_header = '>ii' # 以大端法读取两个 unsinged int32 magic_number, label_num = struct.unpack_from(fmt_header, fb_data, offset) print('idex1 魔数:{},标签数:{}'.format(magic_number, label_num)) offset += struct.calcsize(fmt_header) labels = np.empty(shape=[0,10],dtype=float) #神经网络需要把label变成10位float的数组 fmt_label = '>B' # 每次读取一个 byte for i in range(label_num): n=struct.unpack_from(fmt_label, fb_data, offset) labels=np.append(labels,[[0,0,0,0,0,0,0,0,0,0]],axis=0) labels[i][n]=1 offset += struct.calcsize(fmt_label) return labels def __init__(self): #固定的训练文件位置 self.img=self.decode_idx3_ubyte("/home/zhangyl/Downloads/mnist/train-images.idx3-ubyte") self.result=self.decode_idx1_ubyte("/home/zhangyl/Downloads/mnist/train-labels.idx1-ubyte") print(self.result[0]) print(self.result[1000]) print(self.result[25000]) #固定的验证文件位置 self.validate_img=self.decode_idx3_ubyte("/home/zhangyl/Downloads/mnist/t10k-images.idx3-ubyte") self.validate_result=self.decode_idx1_ubyte("/home/zhangyl/Downloads/mnist/t10k-labels.idx1-ubyte") #每一批读训练数据的起始位置 self.train_read_addr=0 #每一批读训练数据的batchsize self.train_batchsize=100 #每一批读验证数据的起始位置 self.validate_read_addr=0 #每一批读验证数据的batchsize self.validate_batchsize=100 #定义用于返回batch数据的变量 self.train_img_batch=self.img self.train_result_batch=self.result self.validate_img_batch=self.validate_img self.validate_result_batch=self.validate_result def get_next_batch_traindata(self): n=len(self.img) #对参数范围适当约束 if self.train_read_addr+self.train_batchsize<=n : self.train_img_batch=self.img[self.train_read_addr:self.train_read_addr+self.train_batchsize] self.train_result_batch=self.result[self.train_read_addr:self.train_read_addr+self.train_batchsize] self.train_read_addr+=self.train_batchsize #改变起始位置 if self.train_read_addr==n : self.train_read_addr=0 else: self.train_img_batch=self.img[self.train_read_addr:n] self.train_img_batch.append(self.img[0:self.train_read_addr+self.train_batchsize-n]) self.train_result_batch=self.result[self.train_read_addr:n] self.train_result_batch.append(self.result[0:self.train_read_addr+self.train_batchsize-n]) self.train_read_addr=self.train_read_addr+self.train_batchsize-n #改变起始位置,这里没考虑batchsize大于n的情形 return self.train_img_batch,self.train_result_batch #测试一下用临时变量返回是否可行 def set_train_read_addr(self,addr): self.train_read_addr=addr def set_train_batchsize(self,batchsize): self.train_batchsize=batchsize if batchsize <1 : self.train_batchsize=1 def set_validate_read_addr(self,addr): self.validate_read_addr=addr def set_validate_batchsize(self,batchsize): self.validate_batchsize=batchsize if batchsize<1 : self.validate_batchsize=1 myminst=MyMinst() #minst类的实例 batch_size=2 #设置每一轮训练的Batch大小 learning_rate=0.8 #初始学习率 learning_rate_decay=0.999 #学习率的衰减 max_steps=300000 #最大训练步数 #定义存储训练轮数的变量,在使用tensorflow训练神经网络时, #一般会将代表训练轮数的变量通过trainable参数设置为不可训练的 training_step = tf.Variable(0,trainable=False) #定义得到隐藏层和输出层的前向传播计算方式,激活函数使用relu() def hidden_layer(input_tensor,weights1,biases1,weights2,biases2,layer_name): layer1=tf.nn.relu(tf.matmul(input_tensor,weights1)+biases1) return tf.matmul(layer1,weights2)+biases2 x=tf.placeholder(tf.float32,[None,784],name="x-input") y_=tf.placeholder(tf.float32,[None,10],name="y-output") #生成隐藏层参数,其中weights包含784*500=39200个参数 weights1=tf.Variable(tf.truncated_normal([784,500],stddev=0.1)) biases1=tf.Variable(tf.constant(0.1,shape=[500])) #生成输出层参数,其中weights2包含500*10=5000个参数 weights2=tf.Variable(tf.truncated_normal([500,10],stddev=0.1)) biases2=tf.Variable(tf.constant(0.1,shape=[10])) #计算经过神经网络前后向传播后得到的y值 y=hidden_layer(x,weights1,biases1,weights2,biases2,'y') #初始化一个滑动平均类,衰减率为0.99 #为了使模型在训练前期可以更新的更快,这里提供了num_updates参数,并设置为当前网络的训练轮数 #averages_class=tf.train.ExponentialMovingAverage(0.99,training_step) #定义一个更新变量滑动平均值的操作需要向滑动平均类的apply()函数提供一个参数列表 #train_variables()函数返回集合图上Graph.TRAINABLE_VARIABLES中的元素。 #这个集合的元素就是所有没有指定trainable_variables=False的参数 #averages_op=averages_class.apply(tf.trainable_variables()) #再次计算经过神经网络前向传播后得到的y值,这里使用了滑动平均,但要牢记滑动平均值只是一个影子变量 #average_y=hidden_layer(x,averages_class.average(weights1), # averages_class.average(biases1), # averages_class.average(weights2), # averages_class.average(biases2), # 'average_y') #softmax,计算交叉熵损失,L2正则,随机梯度优化器,学习率采用指数衰减 #函数原型为sparse_softmax_cross_entropy_with_logits(_sential,labels,logdits,name) #与softmax_cross_entropy_with_logits()函数的计算方式相同,更适用于每个类别相互独立且排斥 #的情况,即每一幅图只能属于一类 #在1.0.0版本的TensorFlow中,这个函数只能通过命名参数的方式来使用,在这里logits参数是神经网 #络不包括softmax层的前向传播结果,lables参数给出了训练数据的正确答案 softmax=tf.nn.softmax(y) cross_entropy=tf.nn.sparse_softmax_cross_entropy_with_logits(logits=y+1e-10,labels=tf.argmax(y_,1)) #argmax()函数原型为argmax(input,axis,name,dimension)用于计算每一个样例的预测答案,其中 # input参数y是一个batch_size*10(batch_size行,10列)的二维数组。每一行表示一个样例前向传 # 播的结果,axis参数“1”表示选取最大值的操作只在第一个维度进行。即只在每一行选取最大值对应的下标 # 于是得到的结果是一个长度为batch_size的一维数组,这个一维数组的值就表示了每一个样例的数字识别 # 结果。 regularizer=tf.contrib.layers.l2_regularizer(0.0001) #计算L2正则化损失函数 regularization=regularizer(weights1)+regularizer(weights2) #计算模型的正则化损失 loss=tf.reduce_mean(cross_entropy)#+regularization #总损失 #用指数衰减法设置学习率,这里staircase参数采用默认的False,即学习率连续衰减 learning_rate=tf.train.exponential_decay(learning_rate,training_step, batch_size,learning_rate_decay) #使用GradientDescentOptimizer优化算法来优化交叉熵损失和正则化损失 train_op=tf.train.GradientDescentOptimizer(learning_rate).minimize(loss, global_step=training_step) #在训练这个模型时,每过一遍数据既需要通过反向传播来更新神经网络中的参数,又需要 # 更新每一个参数的滑动平均值。control_dependencies()用于这样的一次性多次操作 #同样的操作也可以使用下面这行代码完成: #train_op=tf.group(train_step,average_op) #with tf.control_dependencies([train_step,averages_op]): # train_op=tf.no_op(name="train") #检查使用了滑动平均模型的神经网络前向传播结果是否正确 #equal()函数原型为equal(x,y,name),用于判断两个张量的每一维是否相等。 #如果相等返回True,否则返回False crorent_predicition=tf.equal(tf.argmax(y,1),tf.argmax(y_,1)) #cast()函数的原型为cast(x,DstT,name),在这里用于将一个布尔型的数据转换为float32类型 #之后对得到的float32型数据求平均值,这个平均值就是模型在这一组数据上的正确率 accuracy=tf.reduce_mean(tf.cast(crorent_predicition,tf.float32)) #创建会话和开始训练过程 with tf.Session() as sess: #在稍早的版本中一般使用initialize_all_variables()函数初始化全部变量 tf.global_variables_initializer().run() #准备验证数据 validate_feed={x:myminst.validate_img,y_:myminst.validate_result} #准备测试数据 test_feed= {x:myminst.img,y_:myminst.result} for i in range(max_steps): if i%1000==0: #计算滑动平均模型在验证数据上的结果 #为了能得到百分数输出,需要将得到的validate_accuracy扩大100倍 validate_accuracy= sess.run(accuracy,feed_dict=validate_feed) print("After %d trainning steps,validation accuracy using average model is %g%%" %(i,validate_accuracy*100)) #产生这一轮使用一个batch的训练数据,并进行训练 #input_data.read_data_sets()函数生成的类提供了train.next_batch()函数 #通过设置函数的batch_size参数就可以从所有的训练数据中读取一个小部分作为一个训练batch myminst.set_train_batchsize(batch_size) xs,ys=myminst.get_next_batch_traindata() var_print=sess.run([x,y,y_,loss,train_op,softmax,cross_entropy,regularization,weights1],feed_dict={x:xs,y_:ys}) print("after ",i," trainning steps:") print("x=",var_print[0][0],var_print[0][1],"y=",var_print[1],"y_=",var_print[2],"loss=",var_print[3], "softmax=",var_print[5],"cross_entropy=",var_print[6],"regularization=",var_print[7],var_print[7]) time.sleep(0.5) #使用测试数据集检验神经网络训练之后的正确率 #为了能得到百分数输出,需要将得到的test_accuracy扩大100倍 test_accuracy=sess.run(accuracy,feed_dict=test_feed) print("After %d training steps,test accuracy using average model is %g%%"%(max_steps,test_accuracy*100)) 下面是运行情况的一部分: x= [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 8. 76. 202. 254. 255. 163. 37. 2. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 13. 182. 253. 253. 253. 253. 253. 253. 23. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 15. 179. 253. 253. 212. 91. 218. 253. 253. 179. 109. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 105. 253. 253. 160. 35. 156. 253. 253. 253. 253. 250. 113. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 19. 212. 253. 253. 88. 121. 253. 233. 128. 91. 245. 253. 248. 114. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 104. 253. 253. 110. 2. 142. 253. 90. 0. 0. 26. 199. 253. 248. 63. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1. 173. 253. 253. 29. 0. 84. 228. 39. 0. 0. 0. 72. 251. 253. 215. 29. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 36. 253. 253. 203. 13. 0. 0. 0. 0. 0. 0. 0. 0. 82. 253. 253. 170. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 36. 253. 253. 164. 0. 0. 0. 0. 0. 0. 0. 0. 0. 11. 198. 253. 184. 6. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 36. 253. 253. 82. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 138. 253. 253. 35. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 128. 253. 253. 47. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 48. 253. 253. 35. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 154. 253. 253. 47. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 48. 253. 253. 35. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 102. 253. 253. 99. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 48. 253. 253. 35. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 36. 253. 253. 164. 0. 0. 0. 0. 0. 0. 0. 0. 0. 16. 208. 253. 211. 17. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 32. 244. 253. 175. 4. 0. 0. 0. 0. 0. 0. 0. 0. 44. 253. 253. 156. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 171. 253. 253. 29. 0. 0. 0. 0. 0. 0. 0. 30. 217. 253. 188. 19. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 171. 253. 253. 59. 0. 0. 0. 0. 0. 0. 60. 217. 253. 253. 70. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 78. 253. 253. 231. 48. 0. 0. 0. 26. 128. 249. 253. 244. 94. 15. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 8. 151. 253. 253. 234. 101. 121. 219. 229. 253. 253. 201. 80. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 38. 232. 253. 253. 253. 253. 253. 253. 253. 201. 66. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 232. 253. 253. 95. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 3. 86. 46. 0. 0. 0. 0. 0. 0. 91. 246. 252. 232. 57. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 103. 252. 187. 13. 0. 0. 0. 0. 22. 219. 252. 252. 175. 0. 0. 0. 0. 0. 0. 0. 0. 0. 10. 0. 0. 0. 0. 8. 181. 252. 246. 30. 0. 0. 0. 0. 65. 252. 237. 197. 64. 0. 0. 0. 0. 0. 0. 0. 0. 0. 87. 0. 0. 0. 13. 172. 252. 252. 104. 0. 0. 0. 0. 5. 184. 252. 67. 103. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 8. 172. 252. 248. 145. 14. 0. 0. 0. 0. 109. 252. 183. 137. 64. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 5. 224. 252. 248. 134. 0. 0. 0. 0. 0. 53. 238. 252. 245. 86. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 12. 174. 252. 223. 88. 0. 0. 0. 0. 0. 0. 209. 252. 252. 179. 9. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 11. 171. 252. 246. 61. 0. 0. 0. 0. 0. 0. 83. 241. 252. 211. 14. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 129. 252. 252. 249. 220. 220. 215. 111. 192. 220. 221. 243. 252. 252. 149. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 144. 253. 253. 253. 253. 253. 253. 253. 253. 253. 255. 253. 226. 153. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 44. 77. 77. 77. 77. 77. 77. 77. 77. 153. 253. 235. 32. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 74. 214. 240. 114. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 24. 221. 243. 57. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 8. 180. 252. 119. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 136. 252. 153. 7. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 3. 136. 251. 226. 34. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 123. 252. 246. 39. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 165. 252. 127. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 165. 175. 3. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] y= [[ 0.58273095 0.50121385 -0.74845004 0.35842288 -0.13741069 -0.5839622 0.2642774 0.5101677 -0.29416046 0.5471707 ] [ 0.58273095 0.50121385 -0.74845004 0.35842288 -0.13741069 -0.5839622 0.2642774 0.5101677 -0.29416046 0.5471707 ]] y_= [[1. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [0. 0. 0. 0. 1. 0. 0. 0. 0. 0.]] loss= 2.2801425 softmax= [[0.14659645 0.13512042 0.03872566 0.11714067 0.07134604 0.04564939 0.10661562 0.13633572 0.06099501 0.14147504] [0.14659645 0.13512042 0.03872566 0.11714067 0.07134604 0.04564939 0.10661562 0.13633572 0.06099501 0.14147504]] cross_entropy= [1.9200717 2.6402135] regularization= 50459690000000.0 50459690000000.0 after 45 trainning steps: x= [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 25. 214. 225. 90. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 7. 145. 212. 253. 253. 60. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 106. 253. 253. 246. 188. 23. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 45. 164. 254. 253. 223. 108. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 24. 236. 253. 252. 124. 28. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 100. 217. 253. 218. 116. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 158. 175. 225. 253. 92. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 24. 217. 241. 248. 114. 2. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 21. 201. 253. 253. 114. 3. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 107. 253. 253. 213. 19. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 170. 254. 254. 169. 0. 0. 0. 0. 0. 2. 13. 100. 133. 89. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 18. 210. 253. 253. 100. 0. 0. 0. 19. 76. 116. 253. 253. 253. 176. 4. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 41. 222. 253. 208. 18. 0. 0. 93. 209. 232. 217. 224. 253. 253. 241. 31. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 157. 253. 253. 229. 32. 0. 154. 250. 246. 36. 0. 49. 253. 253. 168. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 128. 253. 253. 253. 195. 125. 247. 166. 69. 0. 0. 37. 236. 253. 168. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 37. 253. 253. 253. 253. 253. 135. 32. 0. 7. 130. 73. 202. 253. 133. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 7. 185. 253. 253. 253. 253. 64. 0. 10. 210. 253. 253. 253. 153. 9. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 66. 253. 253. 253. 253. 238. 218. 221. 253. 253. 235. 156. 37. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 5. 111. 228. 253. 253. 253. 253. 254. 253. 168. 19. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 9. 110. 178. 253. 253. 249. 63. 5. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 121. 121. 240. 253. 218. 121. 121. 44. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 17. 107. 184. 240. 253. 252. 252. 252. 252. 252. 252. 219. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 75. 122. 230. 252. 252. 252. 253. 252. 252. 252. 252. 252. 252. 239. 56. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 77. 129. 213. 244. 252. 252. 252. 252. 252. 253. 252. 252. 209. 252. 252. 252. 225. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 240. 252. 252. 252. 252. 252. 252. 213. 185. 53. 53. 53. 89. 252. 252. 252. 120. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 240. 232. 198. 93. 164. 108. 66. 28. 0. 0. 0. 0. 81. 252. 252. 222. 24. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 76. 50. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 171. 252. 243. 108. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 144. 238. 252. 115. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 7. 70. 241. 248. 133. 28. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 121. 252. 252. 172. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 64. 255. 253. 209. 21. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 13. 246. 253. 207. 21. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 10. 172. 252. 209. 92. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 13. 168. 252. 252. 92. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 43. 208. 252. 241. 53. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 15. 166. 252. 204. 62. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 13. 166. 243. 191. 29. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 10. 168. 231. 177. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 6. 172. 241. 50. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 177. 202. 19. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] y= [[ 0.8592988 0.3954708 -0.77875614 0.26675048 0.19804694 -0.61968666 0.18084174 0.4034736 -0.34189415 0.43645462] [ 0.8592988 0.3954708 -0.77875614 0.26675048 0.19804694 -0.61968666 0.18084174 0.4034736 -0.34189415 0.43645462]] y_= [[0. 0. 0. 0. 0. 0. 1. 0. 0. 0.] [0. 0. 0. 0. 0. 0. 0. 1. 0. 0.]] loss= 2.2191708 softmax= [[0.19166051 0.12052987 0.0372507 0.10597225 0.09893605 0.04367344 0.09724841 0.12149832 0.05765821 0.12557226] [0.19166051 0.12052987 0.0372507 0.10597225 0.09893605 0.04367344 0.09724841 0.12149832 0.05765821 0.12557226]] cross_entropy= [2.3304868 2.1078548] regularization= 50459690000000.0 50459690000000.0 after 46 trainning steps: x= [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 196. 99. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 5. 49. 0. 0. 0. 0. 0. 0. 34. 244. 98. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 89. 135. 0. 0. 0. 0. 0. 0. 40. 253. 98. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 171. 150. 0. 0. 0. 0. 0. 0. 40. 253. 98. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 254. 233. 0. 0. 0. 0. 0. 0. 77. 253. 98. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 255. 136. 0. 0. 0. 0. 0. 0. 77. 254. 99. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 254. 135. 0. 0. 0. 0. 0. 0. 123. 253. 98. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 254. 135. 0. 0. 0. 0. 0. 0. 136. 253. 98. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 16. 254. 135. 0. 0. 0. 0. 0. 0. 136. 237. 8. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 98. 254. 135. 0. 0. 38. 99. 98. 98. 219. 155. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 196. 255. 208. 186. 254. 254. 255. 254. 254. 254. 254. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 105. 254. 253. 239. 180. 135. 39. 39. 39. 237. 170. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 137. 92. 24. 0. 0. 0. 0. 0. 234. 155. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 13. 237. 155. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 79. 253. 155. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 31. 242. 155. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 61. 248. 155. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 234. 155. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 234. 155. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 196. 155. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 50. 236. 255. 124. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 53. 231. 253. 253. 107. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 9. 193. 253. 253. 230. 4. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 7. 156. 253. 253. 149. 36. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 24. 253. 253. 190. 8. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 3. 175. 253. 253. 72. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 123. 253. 253. 138. 3. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 10. 244. 253. 230. 34. 0. 9. 24. 23. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 181. 253. 249. 123. 0. 69. 195. 253. 249. 146. 15. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 21. 231. 253. 202. 0. 70. 236. 253. 253. 253. 253. 170. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 22. 139. 253. 213. 26. 13. 200. 253. 253. 183. 252. 253. 220. 22. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 72. 253. 253. 129. 0. 86. 253. 253. 129. 4. 105. 253. 253. 70. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 72. 253. 253. 77. 22. 245. 253. 183. 4. 0. 2. 105. 253. 70. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 132. 253. 253. 11. 24. 253. 253. 116. 0. 0. 1. 150. 253. 70. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 189. 253. 241. 10. 24. 253. 253. 59. 0. 0. 82. 253. 212. 30. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 189. 253. 147. 0. 24. 253. 253. 150. 30. 44. 208. 212. 31. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 189. 253. 174. 3. 7. 185. 253. 253. 227. 247. 184. 30. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 150. 253. 253. 145. 95. 234. 253. 253. 253. 126. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 72. 253. 253. 253. 253. 253. 253. 253. 169. 14. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 5. 114. 240. 253. 253. 234. 135. 44. 3. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] y= [[ 0.7093834 0.30119324 -0.80789334 0.1838598 0.12065991 -0.6538477 0.49587095 0.6995347 -0.38699397 0.33823296] [ 0.7093834 0.30119324 -0.80789334 0.1838598 0.12065991 -0.6538477 0.49587095 0.6995347 -0.38699397 0.33823296]] y_= [[0. 0. 0. 0. 1. 0. 0. 0. 0. 0.] [0. 0. 0. 0. 0. 0. 1. 0. 0. 0.]] loss= 2.2107558 softmax= [[0.16371341 0.10884525 0.03590371 0.09679484 0.09086671 0.04188326 0.1322382 0.16210894 0.05469323 0.11295244] [0.16371341 0.10884525 0.03590371 0.09679484 0.09086671 0.04188326 0.1322382 0.16210894 0.05469323 0.11295244]] cross_entropy= [2.3983614 2.0231504] regularization= 50459690000000.0 50459690000000.0 after 47 trainning steps: x= [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 11. 139. 212. 253. 159. 86. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 34. 89. 203. 253. 252. 252. 252. 252. 74. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 49. 184. 234. 252. 252. 184. 110. 100. 208. 252. 199. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 95. 233. 252. 252. 176. 56. 0. 0. 0. 17. 234. 249. 75. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 220. 253. 178. 54. 4. 0. 0. 0. 0. 43. 240. 243. 50. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 221. 255. 180. 55. 5. 0. 0. 0. 7. 160. 253. 168. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 116. 253. 252. 252. 67. 0. 0. 0. 91. 252. 231. 42. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 32. 190. 252. 252. 185. 38. 0. 119. 234. 252. 54. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 15. 177. 252. 252. 179. 155. 236. 227. 119. 4. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 26. 221. 252. 252. 253. 252. 130. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 32. 229. 253. 255. 144. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 66. 236. 252. 253. 92. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 66. 234. 252. 252. 253. 92. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 19. 236. 252. 252. 252. 253. 92. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 53. 181. 252. 168. 43. 232. 253. 92. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 179. 255. 218. 32. 93. 253. 252. 84. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 81. 244. 239. 33. 0. 114. 252. 209. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 207. 252. 237. 70. 153. 240. 252. 32. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 207. 252. 253. 252. 252. 252. 210. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 61. 242. 253. 252. 168. 96. 12. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 68. 254. 255. 254. 107. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 11. 176. 230. 253. 253. 253. 212. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 28. 197. 253. 253. 253. 253. 253. 229. 107. 14. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 194. 253. 253. 253. 253. 253. 253. 253. 253. 53. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 69. 241. 253. 253. 253. 253. 241. 186. 253. 253. 195. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 10. 161. 253. 253. 253. 246. 40. 57. 231. 253. 253. 195. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 140. 253. 253. 253. 253. 154. 0. 25. 253. 253. 253. 195. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 213. 253. 253. 253. 135. 8. 0. 3. 128. 253. 253. 195. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 77. 238. 253. 253. 253. 7. 0. 0. 0. 116. 253. 253. 195. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 11. 165. 253. 253. 231. 70. 1. 0. 0. 0. 78. 237. 253. 195. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 33. 253. 253. 253. 182. 0. 0. 0. 0. 0. 0. 200. 253. 195. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 98. 253. 253. 253. 24. 0. 0. 0. 0. 0. 0. 42. 253. 195. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 197. 253. 253. 253. 24. 0. 0. 0. 0. 0. 0. 163. 253. 195. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 197. 253. 253. 189. 13. 0. 0. 0. 0. 0. 53. 227. 253. 121. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 197. 253. 253. 114. 0. 0. 0. 0. 0. 21. 227. 253. 231. 27. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 197. 253. 253. 114. 0. 0. 0. 5. 131. 143. 253. 231. 59. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 197. 253. 253. 236. 73. 58. 217. 223. 253. 253. 253. 174. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 197. 253. 253. 253. 253. 253. 253. 253. 253. 253. 253. 48. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 149. 253. 253. 253. 253. 253. 253. 253. 253. 182. 15. 3. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 12. 168. 253. 253. 253. 253. 253. 248. 89. 23. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] y= [[ 0.5813921 0.21609789 -0.8359629 0.10818548 0.44052082 -0.6865921 0.78338754 0.5727978 -0.4297532 0.24992661] [ 0.5813921 0.21609789 -0.8359629 0.10818548 0.44052082 -0.6865921 0.78338754 0.5727978 -0.4297532 0.24992661]] y_= [[0. 0. 0. 0. 0. 0. 0. 0. 1. 0.] [1. 0. 0. 0. 0. 0. 0. 0. 0. 0.]] loss= 2.452383 softmax= [[0.14272858 0.09905256 0.03459087 0.08892009 0.1239742 0.04016358 0.1746773 0.14150718 0.05192496 0.10246069] [0.14272858 0.09905256 0.03459087 0.08892009 0.1239742 0.04016358 0.1746773 0.14150718 0.05192496 0.10246069]] cross_entropy= [2.9579558 1.9468105] regularization= 50459690000000.0 50459690000000.0 已终止 ```
feof函数返回值始终是零???????????????????????
while (!feof(openfile)) { str = fgetc(openfile); str = str + '\10'; fputc(str, openfile); printf("%c", str); if (ferror(openfile)) { perror("Read error"); break; } a = feof(openfile); printf("%d",a ); }
这个函数有什么问题,一调用就中断
一调用就抛出框框: carmain3.0.exe 中的 0x758e4598 处有未经处理的异常: Microsoft C++ 异常: 内存位置 0x0042ef1c 处的 std::invalid_argument。 下面是该函数 void big_car::read(){ fstream big_carfile("big_car.txt",ios::in|ios::out); vector <string> vec; fun_substr(big_carfile," ",vec); vec.resize(9); int i,j; for(i=0,j=0;i<vec.size();i=i+9,j++){ c1[j].num = vec[i]; c1[j].id = vec[i+1]; c1[j].company= vec[i+2]; c1[j].km = atoi(vec[i+3].c_str()); c1[j].oil = stoi(vec[i+4].c_str()); c1[j].cost= stoi(vec[i+5].c_str()); c1[j].road = stoi(vec[i+6].c_str()); c1[j].all_cost =stoi( vec[i+7].c_str()); c1[j].people = stoi(vec[i+8].c_str()); } count_big_car = j+1; big_carfile.close(); big_car为一个car的派生类, 相关头文件,变量已经定义。 内部调用的函数 fun_substr() //功能描述:将指定文件每一行中字段按一定分割符分割的值存至vector //输入:待读取的文件,字段之间的分割符 //输出:获取字段内容的动态数组 //返回值:无 void fun_substr(fstream &file,string str_sep ,vector <string> &vec){ int count =0; string str = ""; string str_temp = ""; int pos = 0; int sep_len = str_sep.length(); int i=0; while(getline(file,str)){ pos = str.find(str_sep); vec.push_back(str.substr(0,pos)); str_temp = str.substr(pos+1,str.length()-pos-sep_len); pos = str_temp.find(str_sep); while(str_temp.compare("")&& (pos!=-1)){ i++; vec.push_back(str_temp.substr(0,pos)); str_temp = str_temp.substr(pos+1,str_temp.length()-pos-sep_len); pos = str_temp.find(str_sep); } vec.push_back(str_temp); } } 已经困扰很久。 求解脱。。!!!!!!!!!!!。。。。。。。。。。。。。
子函数结束后没有返回主函数就崩溃了怎么回事
#include <stdio.h> #include <stdlib.h> #include<string.h> typedef struct reader{ char name[10]; char key[6]; int kind;//普通读者 struct reader *next; }reader; typedef struct bookers{ char name[10]; char key; int kind;//图书管理员 struct bookers *next; }bookers; typedef struct allers{ char name[10]; char key; int kind;//系统管理员 struct allers *next; }allers; typedef struct allbooks{ int read;//记录号 int num;//书号 char name[50];//书名 char write[10];//作者 char pub[30];//出版社 int have;//藏书量 int take;//借出数 struct allbooks *next; }allbooks; void start(reader *head,bookers *_head,allers *head_); void readerstart(reader *head); void online(reader *head,bookers *_head,allers *head_) { gome: printf("\t\t请输入用户名\n"); char name[10];int choice=3; fflush(stdin); scanf("%s",name);////判断普通用户!!!! while(head->next!=NULL)//确认字符串比较返回值 { int a=strcmp(name,head->name); if(a==0) { while(choice>=0) { if(choice==0) { printf("\t\t请重新登录!!\n"); goto gome; } printf("\t\t请输入密码\n"); char key[6]; scanf("%s",key); if(strcmp(key,head->key)==0) {goto in;}//用户管理系统 else { choice--; printf("密码输入错误,您还有%d次机会",choice); } } } else head=head->next; } in: readerstart(head); } void readerstart(reader *head) { printf("****************************************************\n"); printf("\t欢迎进入图书管理系统,您可以进行以下功能:\n"); printf("\t\t\t 1. 用户信息输入\n"); printf("\t\t\t 2. 用户信息修改\n"); printf("\t\t\t 3. 用户信息删除\n"); printf("\t\t\t 4. 用户信息显示\n"); printf("\t\t\t 5. 用户密码修改\n"); printf("\t\t\t 6. 返回主菜单\n"); int choice; printf("请输入您想使用的功能:"); scanf("%d,&choice"); switch(choice) { case 1: break; case 2: break; case 3: break; case 4: break; case 5: break; case 6: break; } } void start(reader *head,bookers *_head,allers *head_) { char a='n'; /* while(a!='y'||a!='Y') {*/ printf("\t\t 欢迎进入图书管理系统\n"); printf(" *********************************************\t\n "); printf("\t\t\t用户登录"); getchar(); online(head,_head,head_); /* printf("\t\t是否退出?"); printf("Y N"); fflush(stdin); scanf("%c",&a); }*/ } void main() { reader *head;bookers *_head;allers *head_; head=(reader *)malloc(sizeof(reader)); strcpy(head->name,"123"); strcpy(head->key,"789"); start(head,_head,head_); printf("欢迎下次使用!"); } 选择6之后并不能退出程序,调试发现start函数中内容运行完了,但是没回到主函数就会崩溃。 ![图片说明](https://img-ask.csdn.net/upload/201603/02/1456907104_274708.jpg)
就剩这个问题没解决了:TypeError: 'function' object is not subscriptable拜托请教大家!
![图片说明](https://img-ask.csdn.net/upload/201912/07/1575709842_231822.png)![图片说明](https://img-ask.csdn.net/upload/201912/07/1575709860_77315.png) import pandas as pd import numpy as np from GM11 import GM11 # 引入自己编写的灰色预测函数 data = pd.read_csv('D:\\软件\\python\\《Python数据分析与挖掘实战(张良均等)》中文PDF+源代码\\' '《Python数据分析与挖掘实战(张良均等)》中文PDF+源代码\\数据及代码\\chapter13\\test\\data\\data1.csv',engine='python') data.index = range(1994,2014) data data.loc[2014] = None data.loc[2015] = None h = ['x1', 'x2', 'x3', 'x4', 'x5', 'x7'] P = [] C = [] for i in h: gm = GM11(data[i][:-2].values)[0] # 利用返回的灰色预测函数,仅和对对应期数及位置有关 f = gm([0] ) ##获得灰色预测函数 P = gm[-1] # 获得小残差概率 C = gm[-2] # 获得后验比差值 data[i][2014] = f(len(data) - 1) data[i][2015] = f(len(data)) data[i] = data[i].round(2) if (C < 0.35 and P > 0.95): # 评测后验差判别 print( '对于模型%s,该模型精度为---好' % i) elif (C < 0.5 and P > 0.8): print('对于模型%s,该模型精度为---合格' % i) elif (C < 0.65 and P > 0.7): print('对于模型%s,该模型精度为---勉强合格' % i) else: print('对于模型%s,该模型精度为---不合格' % i) data[h + ['y']].to_excel('D:\\软件\\python\\《Python数据分析与挖掘实战(张良均等)》中文PDF+源代码\\' '《Python数据分析与挖掘实战(张良均等)》中文PDF+源代码\\数据及代码\\chapter13\\test\\data\\2_1_2_1greyPredict(最新5).xlsx') 补充: gm为自定义函数: def GM11(x0): #自定义灰色预测函数 import numpy as np x1 = x0.cumsum() #1-AGO序列 z1 = (x1[:len(x1)-1] + x1[1:])/2.0 #紧邻均值(MEAN)生成序列 z1 = z1.reshape((len(z1),1)) B = np.append(-z1, np.ones_like(z1), axis = 1) Yn = x0[1:].reshape((len(x0)-1, 1)) [[a],[b]] = np.dot(np.dot(np.linalg.inv(np.dot(B.T, B)), B.T), Yn) #计算参数 f = lambda k: (x0[0]-b/a)*np.exp(-a*(k-1))-(x0[0]-b/a)*np.exp(-a*(k-2)) #还原值 delta = np.abs(x0 - np.array([f(i) for i in range(1,len(x0)+1)])) C = delta.std()/x0.std() P = 1.0*(np.abs(delta - delta.mean()) < 0.6745*x0.std()).sum()/len(x0) return f, a, b, x0[0], C, P #返回灰色预测函数、a、b、首项、方差比、小残差概率
重金求解,为什么我接收不到socket服务端返回的信息,代码如下,这个logger.debug("result:"result)为什么总是空,确认了服务端的确返回到了socket,怎样才能正确从socket取到值呢?
这是socket客户端代码 ``` import java.io.BufferedReader; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.Socket; import java.net.UnknownHostException; import java.util.Scanner; public class Client extends Thread { Socket socket = null; public String result = ""; public String in = ""; public Client(String host, int port, String in) { try { in = new String(in.getBytes(),"GBK"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } this.in = in; try { socket = new Socket(host, port); socket.setSoTimeout(1000); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } // public void shutDown() throws IOException { // if (socket != null) { // synchronized (socket) { // socket.close(); // } // } // System.out.println("StopClose.shutDown() complete"); // } @Override public void run() { new sendMessThread().start(); super.run(); try { InputStream s = socket.getInputStream(); byte[] buf = new byte[1024]; int len = 0; while ((len = s.read(buf)) != -1) { System.out.println(new String(buf, 0, len)); } } catch (IOException e) { e.printStackTrace(); } } class sendMessThread extends Thread{ @Override public void run() { super.run(); Scanner scanner=null; OutputStream os= null; try { scanner=new Scanner(System.in); os= socket.getOutputStream(); // String in; // do { // in=scanner.next(); // os.write((""+in).getBytes()); // os.flush(); // } while (!in.equals("bye")); for(int i =0;i<1;i++) { os.write((""+in).getBytes()); os.flush(); } BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream(),"GBK")); String str = ""; System.out.println("RESULT AS FOLLOWING:"); while ((str = rd.readLine()) != null) { System.out.println(str); } // str = rd.readLine(); Client.this.result = str; System.out.println("Client.this.result:"+Client.this.result); rd.close(); } catch (IOException e) { e.printStackTrace(); } scanner.close(); try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } public static void main(String[] args) { // Client clientTest=new Client("88.6.13.66", 13000); // Client clientTest=new Client("127.0.0.1", 1234,""); // clientTest.start(); } } ``` 这是调用的代码 ``` import java.io.BufferedReader; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.net.Socket; import java.net.UnknownHostException; import java.util.Scanner; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.sql.Connection; import java.sql.Types; import java.text.NumberFormat; import java.util.ArrayList; import java.util.List; public class FaceCheckManage { private final static String DB_ALIAS = "ALIAS";//数据源 private static final String TRXZONE = "trxZone";//输入|地区号 private static final String TYPE = "type";//输入|操作类型 add-注册 check-识别 del-删除 private static final String IMG = "img";//输入|人脸数据 private static final String ID = "id";//输入|编号 private static final String VALUE = "VALUE";//输出|转发数据 public String process(IWFEngine engine, WFActivity activity, WFData wfd, String wfName) throws ParamNotExistException, com.zjft.bpe.stdlib.exception.UnrecognizedScopeException { BizDataModule dm = wfd.getDataModule(); ZjLogger logger = LoggerUtil.getLog(dm.getChannelId(), dm.getTxCode()); ModuleUtil moduleUtil = new ModuleUtil(wfd, wfd.getDataModule(), activity, logger); String trxZone = moduleUtil.getParamValue(TRXZONE); logger.debug("trxZone:"+trxZone); String type = moduleUtil.getParamValue(TYPE); String imgBase64 = moduleUtil.getParamValue(IMG); String id = moduleUtil.getParamValue(ID); Connection conn = wfd.getTxConnection(moduleUtil.getParamValue(DB_ALIAS)); try { /*是否已注册*/ boolean registedFlag = isRegisted(id, conn, logger); if("add".equals(type)&&registedFlag==true) { CommonUtil.setResponseMsg("FFFFF", "用户已注册,请先删除人脸数据", moduleUtil); return "fail"; }else if(("check".equals(type)||"del".equals(type))&&registedFlag==false) { CommonUtil.setResponseMsg("FFFFF", "用户人脸数据未注册", moduleUtil); return "fail"; } } catch (Exception e) { logger.error("查询是否已注册发生异常",e); CommonUtil.setResponseMsg("FFFFF", "查询是否已注册发生异常", moduleUtil); return "fail"; } JSONObject sysParams = null;//系统参数列表 try { //获取人脸识别配置参数 sysParams = getSysParam(type,conn, logger); }catch (TradeException e) { CommonUtil.setResponseMsg("FFFFF", e.getMessage(), moduleUtil); return "fail"; } catch (Exception e) { logger.error("查询人脸识别系统参数发生异常",e); CommonUtil.setResponseMsg("FFFFF", "查询人脸识别系统参数发生异常", moduleUtil); return "fail"; } String ip = sysParams.getString("ip"); String url =sysParams.getString("url"); //组参数 JSONObject paramMap = new JSONObject(); if("add".equals(type)) { paramMap.put("trxZone", trxZone); paramMap.put("programName", "e"); paramMap.put("id", id); paramMap.put("img1", imgBase64); paramMap.put("imgFace1", "50,60,100,120"); paramMap.put("hack1", 1); paramMap.put("customerAgreement", 1); String trxString = "10032"; String jsonString = paramMap.toJSONString(); int length = jsonString.length()+10; String lenString = getLenString(length); String totalString = trxString+lenString+jsonString; logger.debug("totalString:"+totalString); Client client = new Client("88.6.13.66", 13000,totalString); client.start(); String result = client.result; logger.debug("result:"+result); result = result.substring(5,result.length()); moduleUtil.setParamValue(VALUE, result); logger.debug("VALUE:"+result); JSONObject resultJsonObject = JSONObject.parseObject(result); logger.debug("resultJsonObject:"+resultJsonObject); //新增参数 }else if("check".equals(type)) { paramMap.put("trxZone", trxZone); paramMap.put("programName", "e"); paramMap.put("id", id); paramMap.put("img1", imgBase64); paramMap.put("imgFace1", "50,60,100,120"); paramMap.put("threshold", 0.001); paramMap.put("hack1", 1); String trxString = "10034"; String jsonString = paramMap.toJSONString(); int length = jsonString.length()+10; String lenString = getLenString(length); String totalString = trxString+lenString+jsonString; logger.debug("totalString:"+totalString); Client client = new Client("88.6.13.66", 13000,totalString); client.start(); String result = client.result; logger.debug("result:"+result); result = result.substring(5,result.length()); moduleUtil.setParamValue(VALUE, result); logger.debug("VALUE:"+result); JSONObject resultJsonObject = JSONObject.parseObject(result); logger.debug("resultJsonObject:"+resultJsonObject); }else if("del".equals(type)){ paramMap.put("trxZone", trxZone); paramMap.put("programName", "e"); paramMap.put("id", id); String trxString = "10035"; String jsonString = paramMap.toJSONString(); int length = jsonString.length()+10; String lenString = getLenString(length); String totalString = trxString+lenString+jsonString; logger.debug("totalString:"+totalString); try { totalString = new String(totalString.getBytes(),"GBK"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } Client client = new Client("88.6.13.66", 13000,totalString); client.start(); String result = client.result; logger.debug("result:"+result); result = result.substring(5,result.length()); moduleUtil.setParamValue(VALUE, result); logger.debug("VALUE:"+result); JSONObject resultJsonObject = JSONObject.parseObject(result); logger.debug("resultJsonObject:"+resultJsonObject); }else { CommonUtil.setResponseMsg("FFFFF", "错误的操作类型", moduleUtil); return "fail"; } String param = paramMap.toJSONString(); try { param = "params="+URLEncoder.encode(param,"UTF-8"); } catch (UnsupportedEncodingException e) { logger.error("转换为请求数据失败"); return "fail"; } return "ok"; } /** * <p> 函数名:isRegisted </p> * <p> 函数功能:查询该编号用户人脸信息是否已注册 </p> * <p> 处理过程:(描述这个方法的处理逻辑)</p> * <p> 输入参数描述: </p> * <p> 输出参数描述: </p> * <p> 异常处理描述: </p> * <p> 创建信息:liuyuan/2019年6月4日 下午3:29:48/versoin</p> * <p> 修改信息:(修改人名、修改人名.../最后修改时间/修改版本号)</p> * <p> 多个版本修改,则每次新增一行修改信息</p> * @throws Exception */ private boolean isRegisted(String id,Connection conn,ZjLogger logger) throws Exception { String sql = "select t.id from USER_FACE_RECORD t where t.id_number=? or t.user_no=?"; List<SQLPara> sqlParas = new ArrayList<>(); sqlParas.add(new SQLPara("id_number", Types.VARCHAR, id)); sqlParas.add(new SQLPara("user_no", Types.VARCHAR, id)); CachedRowSet rlt = DbOperate.executeQueryByParamName(sql, sqlParas, conn, logger); return rlt.next(); } /** * * <p>Title: getSysParam</p> * <p>Description: 查询人脸识别相关参数 </p> * @param type * @param conn * @param logger * @return * @throws TradeException * @throws Exception */ private JSONObject getSysParam(String type,Connection conn, ZjLogger logger) throws TradeException,Exception { JSONObject sysParam = new JSONObject(); String qrySysParamSQL = " select t.param_value from SYS_PARAM t where t.param_name=? "; List<SQLPara> sqlParas = new ArrayList<>(); // 查询ip sqlParas.add(new SQLPara("param_name", Types.VARCHAR, "faceCheck_ip")); CachedRowSet ipRlt = DbOperate.executeQueryByParamName(qrySysParamSQL, sqlParas, conn, logger); if (!ipRlt.next()) { throw new TradeException("请先配置人脸识别服务器地址(faceCheck_ip)"); } sysParam.put("ip",ipRlt.getString("param_value")); sqlParas.clear(); // 查询url sqlParas.add(new SQLPara("param_name", Types.VARCHAR, "faceCheck_url")); CachedRowSet urlRlt = DbOperate.executeQueryByParamName(qrySysParamSQL, sqlParas, conn, logger); if (!urlRlt.next()) { throw new TradeException("请先配置人脸识别转发url(faceCheck_url)"); } sysParam.put("url",urlRlt.getString("param_value")); sqlParas.clear(); // 查询baseFlag sqlParas.add(new SQLPara("param_name", Types.VARCHAR, "faceCheck_baseFlag")); CachedRowSet baseFlagRlt = DbOperate.executeQueryByParamName(qrySysParamSQL, sqlParas, conn, logger); if (!baseFlagRlt.next()) { throw new TradeException("请先配置人脸识基准照标示(faceCheck_baseFlag)"); } sysParam.put("baseFlag",baseFlagRlt.getInt("param_value")); sqlParas.clear(); // 查询threshold sqlParas.add(new SQLPara("param_name", Types.VARCHAR, "faceCheck_threshold")); CachedRowSet thresholdRlt = DbOperate.executeQueryByParamName(qrySysParamSQL, sqlParas, conn, logger); if (!thresholdRlt.next()) { throw new TradeException("请先配置人脸识误识率阈值(faceCheck_threshold)"); } sysParam.put("threshold",thresholdRlt.getString("param_value")); sqlParas.clear(); //查询channel sqlParas.add(new SQLPara("param_name", Types.VARCHAR, "faceCheck_channel")); CachedRowSet channelRlt = DbOperate.executeQueryByParamName(qrySysParamSQL, sqlParas, conn, logger); if (!channelRlt.next()) { throw new TradeException("请先配置人脸识别转发业务渠道编号(faceCheck_channel)"); } sysParam.put("channel",channelRlt.getString("param_value")); sqlParas.clear(); //交易编号写死,加操作类型大写进行区分 sysParam.put("trCode","SXFH-BF-SWXJ-ITMS-FACE-"+type.toUpperCase()); //查询appName sqlParas.add(new SQLPara("param_name", Types.VARCHAR, "faceCheck_appName")); CachedRowSet appNameRlt = DbOperate.executeQueryByParamName(qrySysParamSQL, sqlParas, conn, logger); if (!appNameRlt.next()) { throw new TradeException("请先配置人脸识别应用名(faceCheck_appName)"); } sysParam.put("appName",appNameRlt.getString("param_value")); sqlParas.clear(); //查询appInfo sqlParas.add(new SQLPara("param_name", Types.VARCHAR, "faceCheck_appInfo")); CachedRowSet appInfoRlt = DbOperate.executeQueryByParamName(qrySysParamSQL, sqlParas, conn, logger); if (!appInfoRlt.next()) { throw new TradeException("请先配置人脸识别客户端APP信息(faceCheck_appInfo)"); } sysParam.put("appInfo",appInfoRlt.getString("param_value")); sqlParas.clear(); //查询retentionTime sqlParas.add(new SQLPara("param_name", Types.VARCHAR, "faceCheck_retentionTime")); CachedRowSet retentionTimeRlt = DbOperate.executeQueryByParamName(qrySysParamSQL, sqlParas, conn, logger); if (!retentionTimeRlt.next()) { throw new TradeException("请先配置人脸识清理时间(faceCheck_retentionTime)"); } sysParam.put("retentionTime",retentionTimeRlt.getString("param_value")); sqlParas.clear(); logger.debug("sysParam:"+sysParam); return sysParam; } public String getLenString (int length) { NumberFormat formatter = NumberFormat.getNumberInstance(); formatter.setMinimumIntegerDigits(5); formatter.setGroupingUsed(false); String lenString = formatter.format(length); return lenString; } } ``` 这个地方为什么总是空的 ![图片说明](https://img-ask.csdn.net/upload/201912/12/1576144606_651895.png)
动态规划入门到熟悉,看不懂来打我啊
持续更新。。。。。。 2.1斐波那契系列问题 2.2矩阵系列问题 2.3跳跃系列问题 3.1 01背包 3.2 完全背包 3.3多重背包 3.4 一些变形选讲 2.1斐波那契系列问题 在数学上,斐波纳契数列以如下被以递归的方法定义:F(0)=0,F(1)=1, F(n)=F(n-1)+F(n-2)(n&gt;=2,n∈N*)根据定义,前十项为1, 1, 2, 3...
130 个相见恨晚的超实用网站,一次性分享出来
相见恨晚的超实用网站 持续更新中。。。
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它是一个过程,是一个不断累积、不断沉淀、不断总结、善于传达自己的个人见解以及乐于分享的过程。
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过...
Python——画一棵漂亮的樱花树(不同种樱花+玫瑰+圣诞树喔)
最近翻到一篇知乎,上面有不少用Python(大多是turtle库)绘制的树图,感觉很漂亮,我整理了一下,挑了一些我觉得不错的代码分享给大家(这些我都测试过,确实可以生成) one 樱花树 动态生成樱花 效果图(这个是动态的): 实现代码 import turtle as T import random import time # 画樱花的躯干(60,t) def Tree(branch, ...
大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了
大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看...
我在支付宝花了1分钟,查到了女朋友的开房记录!
在大数据时代下,不管你做什么都会留下蛛丝马迹,只要学会把各种软件运用到极致,捉奸简直轻而易举。今天就来给大家分享一下,什么叫大数据抓出轨。据史料证明,马爸爸年轻时曾被...
shell脚本:备份数据库、代码上线
备份MySQL数据库 场景: 一台MySQL服务器,跑着5个数据库,在没有做主从的情况下,需要对这5个库进行备份 需求: 1)每天备份一次,需要备份所有的库 2)把备份数据存放到/data/backup/下 3)备份文件名称格式示例:dbname-2019-11-23.sql 4)需要对1天以前的所有sql文件压缩,格式为gzip 5)本地数据保留1周 6)需要把备份的数据同步到远程备份中心,假如...
聊聊C语言和指针的本质
坐着绿皮车上海到杭州,24块钱,很宽敞,在火车上非正式地聊几句。 很多编程语言都以 “没有指针” 作为自己的优势来宣传,然而,对于C语言,指针却是与生俱来的。 那么,什么是指针,为什么大家都想避开指针。 很简单, 指针就是地址,当一个地址作为一个变量存在时,它就被叫做指针,该变量的类型,自然就是指针类型。 指针的作用就是,给出一个指针,取出该指针指向地址处的值。为了理解本质,我们从计算机模型说起...
为什么你学不过动态规划?告别动态规划,谈谈我的经验
动态规划难吗?说实话,我觉得很难,特别是对于初学者来说,我当时入门动态规划的时候,是看 0-1 背包问题,当时真的是一脸懵逼。后来,我遇到动态规划的题,看的懂答案,但就是自己不会做,不知道怎么下手。就像做递归的题,看的懂答案,但下不了手,关于递归的,我之前也写过一篇套路的文章,如果对递归不大懂的,强烈建议看一看:为什么你学不会递归,告别递归,谈谈我的经验 对于动态规划,春招秋招时好多题都会用到动态...
程序员一般通过什么途径接私活?
二哥,你好,我想知道一般程序猿都如何接私活,我也想接,能告诉我一些方法吗? 上面是一个读者“烦不烦”问我的一个问题。其实不止是“烦不烦”,还有很多读者问过我类似这样的问题。 我接的私活不算多,挣到的钱也没有多少,加起来不到 20W。说实话,这个数目说出来我是有点心虚的,毕竟太少了,大家轻喷。但我想,恰好配得上“一般程序员”这个称号啊。毕竟苍蝇再小也是肉,我也算是有经验的人了。 唾弃接私活、做外...
字节跳动面试官这样问消息队列:分布式事务、重复消费、顺序消费,我整理了一下
你知道的越多,你不知道的越多 点赞再看,养成习惯 GitHub上已经开源 https://github.com/JavaFamily 有一线大厂面试点脑图、个人联系方式和人才交流群,欢迎Star和完善 前言 消息队列在互联网技术存储方面使用如此广泛,几乎所有的后端技术面试官都要在消息队列的使用和原理方面对小伙伴们进行360°的刁难。 作为一个在互联网公司面一次拿一次Offer的面霸...
2020年大前端发展趋势
迅速发展的前端开发,在每⼀年,都为开发者带来了新的关键词。2019 年已步⼊尾声,2020 年前端发展的关键词⼜将有哪些呢?发展的方向又会是什么呢?参考2019年大前端的发展,不出意外,前端依旧会围绕⼩程序、超级APP、跨端开发、前端⼯程化以及新技术运用等几个方面进行展开(可以参考2019年大前端技术趋势深度解读)。 小程序 在⼩程序⽅⾯,今年仍然是⼩程序突⻜猛进的⼀年,各⼤主流的 App 都上线...
如何安装 IntelliJ IDEA 最新版本——详细教程
IntelliJ IDEA 简称 IDEA,被业界公认为最好的 Java 集成开发工具,尤其在智能代码助手、代码自动提示、代码重构、代码版本管理(Git、SVN、Maven)、单元测试、代码分析等方面有着亮眼的发挥。IDEA 产于捷克,开发人员以严谨著称的东欧程序员为主。IDEA 分为社区版和付费版两个版本。 我呢,一直是 Eclipse 的忠实粉丝,差不多十年的老用户了。很早就接触到了 IDEA...
1个月时间整理了2019年上千道Java面试题,近500页文档!
Spring 面试题 1、一般问题 1.1、不同版本的 spring Framework 有哪些主要功能? 1.2、什么是 spring Framework? 1.3、列举 spring Framework 的优点。 1.4、spring Framework 有哪些不同的功能? 1.5、spring Framework 中有多少个模块,它们分别是什么? 1.6、什么是 spring ...
面试还搞不懂redis,快看看这40道面试题(含答案和思维导图)
Redis 面试题 1、什么是 Redis?. 2、Redis 的数据类型? 3、使用 Redis 有哪些好处? 4、Redis 相比 Memcached 有哪些优势? 5、Memcache 与 Redis 的区别都有哪些? 6、Redis 是单进程单线程的? 7、一个字符串类型的值能存储最大容量是多少? 8、Redis 的持久化机制是什么?各自的优缺点? 9、Redis 常见性...
为什么要推荐大家学习字节码?
配套视频: 为什么推荐大家学习Java字节码 https://www.bilibili.com/video/av77600176/ 一、背景 本文主要探讨:为什么要学习 JVM 字节码? 可能很多人会觉得没必要,因为平时开发用不到,而且不学这个也没耽误学习。 但是这里分享一点感悟,即人总是根据自己已经掌握的知识和技能来解决问题的。 这里有个悖论,有时候你觉得有些技术没用恰恰是...
在阿里,40岁的奋斗姿势
在阿里,40岁的奋斗姿势 在阿里,什么样的年纪可以称为老呢?35岁? 在云网络,有这样一群人,他们的平均年龄接近40,却刚刚开辟职业生涯的第二战场。 他们的奋斗姿势是什么样的呢? 洛神赋 “翩若惊鸿,婉若游龙。荣曜秋菊,华茂春松。髣髴兮若轻云之蔽月,飘飖兮若流风之回雪。远而望之,皎若太阳升朝霞;迫而察之,灼若芙蕖出渌波。” 爱洛神,爱阿里云 2018年,阿里云网络产品部门启动洛神2.0升...
【超详细分析】关于三次握手与四次挥手面试官想考我们什么?
在面试中,三次握手和四次挥手可以说是问的最频繁的一个知识点了,我相信大家也都看过很多关于三次握手与四次挥手的文章,今天的这篇文章,重点是围绕着面试,我们应该掌握哪些比较重要的点,哪些是比较被面试官给问到的,我觉得如果你能把我下面列举的一些点都记住、理解,我想就差不多了。 三次握手 当面试官问你为什么需要有三次握手、三次握手的作用、讲讲三次三次握手的时候,我想很多人会这样回答: 首先很多人会先讲下握...
压测学习总结(1)——高并发性能指标:QPS、TPS、RT、吞吐量详解
一、QPS,每秒查询 QPS:Queries Per Second意思是“每秒查询率”,是一台服务器每秒能够相应的查询次数,是对一个特定的查询服务器在规定时间内所处理流量多少的衡量标准。互联网中,作为域名系统服务器的机器的性能经常用每秒查询率来衡量。 二、TPS,每秒事务 TPS:是TransactionsPerSecond的缩写,也就是事务数/秒。它是软件测试结果的测量单位。一个事务是指一...
新程序员七宗罪
当我发表这篇文章《为什么每个工程师都应该开始考虑开发中的分析和编程技能呢?》时,我从未想到它会对读者产生如此积极的影响。那些想要开始探索编程和数据科学领域的人向我寻求建议;还有一些人问我下一篇文章的发布日期;还有许多人询问如何顺利过渡到这个职业。我非常鼓励大家继续分享我在这个旅程的经验,学习,成功和失败,以帮助尽可能多的人过渡到一个充满无数好处和机会的职业生涯。亲爱的读者,谢谢你。 -罗伯特。 ...
活到老,学到老,程序员也该如此
全文共2763字,预计学习时长8分钟 图片来源:Pixabay 此前,“网传阿里巴巴要求尽快实现P8全员35周岁以内”的消息闹得沸沸扬扬。虽然很快被阿里辟谣,但苍蝇不叮无缝的蛋,无蜜不招彩蝶蜂。消息从何而来?真相究竟怎样?我们无从而知。我们只知道一个事实:不知从何时开始,程序猿也被划在了“吃青春饭”行业之列。 饱受“996ICU”摧残后,好不容易“头秃了变强了”,即将步入为“高...
Vue快速实现通用表单验证
本文开篇第一句话,想引用鲁迅先生《祝福》里的一句话,那便是:“我真傻,真的,我单单知道后端整天都是CRUD,我没想到前端整天都是Form表单”。这句话要从哪里说起呢?大概要从最近半个月的“全栈工程师”说起。项目上需要做一个城市配载的功能,顾名思义,就是通过框选和拖拽的方式在地图上完成配载。博主选择了前后端分离的方式,在这个过程中发现:首先,只要有依赖jQuery的组件,譬如Kendoui,即使使用...
2019年Spring Boot面试都问了什么?快看看这22道面试题!
Spring Boot 面试题 1、什么是 Spring Boot? 2、Spring Boot 有哪些优点? 3、什么是 JavaConfig? 4、如何重新加载 Spring Boot 上的更改,而无需重新启动服务器? 5、Spring Boot 中的监视器是什么? 6、如何在 Spring Boot 中禁用 Actuator 端点安全性? 7、如何在自定义端口上运行 Sprin...
Unity项目在pc和ios设备上黑屏的原因探究
0x00 由于项目上线了windows平台的项目(别问我为什么,咱也不敢说,咱也不敢问),由Unity5.4.6升级到Unity2018的过程中,遇到了各种各样的坑,本文为避坑指南1。本项目没有使用HDR和抗锯齿,由于查这几个问题查到吐血,前后用了3天的时间,本文充满了怨气,行文非常啰嗦,需要快速解决问题的,可以直接拉到最后看结论。 0x01 法线贴图 项目在unity2018出了新的androi...
关于裁员几点看法及建议
最近网易裁员事件引起广泛关注,昨天网易针对此事,也发了声明,到底谁对谁错,孰是孰非?我们作为吃瓜观众实在是知之甚少,所以不敢妄下定论。身处软件开发这个行业,近一两年来,对...
面试官:关于Java性能优化,你有什么技巧
通过使用一些辅助性工具来找到程序中的瓶颈,然后就可以对瓶颈部分的代码进行优化。 一般有两种方案:即优化代码或更改设计方法。我们一般会选择后者,因为不去调用以下代码要比调用一些优化的代码更能提高程序的性能。而一个设计良好的程序能够精简代码,从而提高性能。 下面将提供一些在JAVA程序的设计和编码中,为了能够提高JAVA程序的性能,而经常采用的一些方法和技巧。 1.对象的生成和大小的调整。 J...
【图解算法面试】记一次面试:说说游戏中的敏感词过滤是如何实现的?
版权声明:本文为苦逼的码农原创。未经同意禁止任何形式转载,特别是那些复制粘贴到别的平台的,否则,必定追究。欢迎大家多多转发,谢谢。 小秋今天去面试了,面试官问了一个与敏感词过滤算法相关的问题,然而小秋对敏感词过滤算法一点也没听说过。于是,有了下下事情的发生… 面试官开怼 面试官:玩过王者荣耀吧?了解过敏感词过滤吗?,例如在游戏里,如果我们发送“你在干嘛?麻痹演员啊你?”,由于“麻痹”是一个敏感词,...
相关热词 c# singleton c#中类的默认值是 c#各种进制之间的转换 c# 正则表达式保留汉字 c#后台跨域 c#基础代码大全 c#指定combox选择 c#关系 mono c# 相差毫秒 用c#做一个简易计算器
立即提问